Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<pre><pre lang="Python">
First of all sorry asking that type of questions

Hi below is the actual request

POST /restapi/soa2/21140/login HTTP/1.1
Host: m.ctrip.com
Connection: close
Content-Length: 70
sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
content-type: application/json;charset:utf-8;
Accept: */*
Origin: https://www.tripadvisor.cn
Sec-Fetch-Site: cross-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: https://www.tripadvisor.cn/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,ar;q=0.8,zh-CN;q=0.7,zh;q=0.6,pt;q=0.5

{"loginType":"sina","externalCode":"4eb3f2cece2d64de27ab166267fb2222"}

and below is the python code for this request

import requests

url = "https://m.ctrip.com:443/restapi/soa2/21140/login"

payload = '{"loginType":"sina","externalCode":"4eb3f2cece2d64de27ab166267fb2222"}'
headers = {
"Origin": "https://www.tripadvisor.cn",
"Accept": "*/*",
"Connection": "close",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36",
"Referer": "https://www.tripadvisor.cn/",
"Sec-Fetch-Site": "cross-site",
"Sec-Fetch-Dest": "empty",
"Host": "m.ctrip.com",
"Accept-Encoding": "gzip, deflate",
"Sec-Fetch-Mode": "cors",
"sec-ch-ua": '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
"sec-ch-ua-mobile": "?0",
"content-type": "application/json;charset:utf-8;",
"Accept-Language": "en-US,en;q=0.9,ar;q=0.8,zh-CN;q=0.7,zh;q=0.6,pt;q=0.5",
"Content-Length": "70",
}

response = requests.request("POST", url, data=payload, headers=headers)

print(response.headers)
Python



and as you see 32ab66b1039cc04a78c49818d4e643f1 this is my auth code and i want to be a script that take this authcode as a user input and replace on externalCode parameter value

and if everything correct it will print a headers as a output

https://i.stack.imgur.com/RZCdp.png

Thanks and help will be appreciated




What I have tried:

import requests

x = input("Enter your code:")

url = "https://m.ctrip.com:443/restapi/soa2/21140/login"

payload = '{"loginType":"sina","externalCode":"print("" + x)"}'
headers = {
    "Origin": "https://www.tripadvisor.cn",
    "Accept": "*/*",
    "Connection": "close",
    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36",
    "Referer": "https://www.tripadvisor.cn/",
    "Sec-Fetch-Site": "cross-site",
    "Sec-Fetch-Dest": "empty",
    "Host": "m.ctrip.com",
    "Accept-Encoding": "gzip, deflate",
    "Sec-Fetch-Mode": "cors",
    "sec-ch-ua": '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
    "sec-ch-ua-mobile": "?0",
    "content-type": "application/json;charset:utf-8;",
    "Accept-Language": "en-US,en;q=0.9,ar;q=0.8,zh-CN;q=0.7,zh;q=0.6,pt;q=0.5",
    "Content-Length": "70",
}

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)




and


import requests

x = input("Enter your code:")

url = "https://m.ctrip.com:443/restapi/soa2/21140/login"

payload = '{"loginType":"sina","externalCode":""" + x"}'
headers = {
    "Origin": "https://www.tripadvisor.cn",
    "Accept": "*/*",
    "Connection": "close",
    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36",
    "Referer": "https://www.tripadvisor.cn/",
    "Sec-Fetch-Site": "cross-site",
    "Sec-Fetch-Dest": "empty",
    "Host": "m.ctrip.com",
    "Accept-Encoding": "gzip, deflate",
    "Sec-Fetch-Mode": "cors",
    "sec-ch-ua": '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
    "sec-ch-ua-mobile": "?0",
    "content-type": "application/json;charset:utf-8;",
    "Accept-Language": "en-US,en;q=0.9,ar;q=0.8,zh-CN;q=0.7,zh;q=0.6,pt;q=0.5",
    "Content-Length": "70",
}

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)



But none of them works
Posted
Updated 18-Aug-21 22:25pm

1 solution

Try using the correct quotes:
Python
payload = '{"loginType":"sina","externalCode":"' + x + '"}'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900