我正在尝试登录,但是出现404 not found错误。我尝试使用Cookie登录,但没有登录并且都无法正常工作。我确定数据正确无误,并通过提取了数据。
我试图操纵标头数据,但没有任何效果。以及我尝试更改用户代理的情况也无法正常工作。所以我在等待您的帮助。
import requests
def Headers():
headerdata = {
'Host': 'api.cathaypacific.com',
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Origin': 'https://www.asiamiles.com',
'Upgrade-Insecure-Requests': '1',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-User': '?1',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Sec-Fetch-Site': 'cross-site',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'ar-EG,ar;q=0.9,en-US;q=0.8,en;q=0.7',
'Content-Length': '368'}
return headerdata
def PostData():
data = 'response_type=code&scope=openid+offline_access&redirect_uri=https%3A%2F%2Fapi.asiamiles.com%2Fprofile%2Fapi%2Fv2%2FcreateSessionAndRedirect&client_id=de07768c-6e6d-4b48-81f3-dbf50618e598&login_url=https%3A%2F%2Fwww.asiamiles.com%2Fen%2Flogin.html&target_url=https%3A%2F%2Fwww.asiamiles.com%2Fen%2Faccount%2Faccount-overview.html&state=&username=1707617679&password=*123qweQWE'
return data
def RequestEstablisher():
url = 'https://api.cathaypacific.com/mlc2/authorize'
opener = requests.sessions.session()
temp = opener.post(url=url,data=PostData(),headers=Headers())
print(temp.status_code,temp.reason)
print(temp.is_redirect)
print(temp.elapsed)
print(temp.headers.get('Location'))
RequestEstablisher()
答案 0 :(得分:0)
如果我排除标题,那么我会得到一个好的响应:
import requests
headers = {
'Host': 'api.cathaypacific.com',
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Origin': 'https://www.asiamiles.com',
'Upgrade-Insecure-Requests': '1',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-User': '?1',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Sec-Fetch-Site': 'cross-site',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'ar-EG,ar;q=0.9,en-US;q=0.8,en;q=0.7',
'Content-Length': '368',
}
post_data = {
'response_type': 'code',
'scope': 'openid+offline_access',
'redirect_uri': 'https%3A%2F%2Fapi.asiamiles.com%2Fprofile%2Fapi%2Fv2%2FcreateSessionAndRedirect',
'client_id': 'de07768c-6e6d-4b48-81f3-dbf50618e598',
'login_url': 'https%3A%2F%2Fwww.asiamiles.com%2Fen%2Flogin.html',
'target_url': 'https%3A%2F%2Fwww.asiamiles.com%2Fen%2Faccount%2Faccount-overview.html',
'state': '',
'username': '1707617679',
'password': '*123qweQWE',
}
url = 'https://api.cathaypacific.com/mlc2/authorize'
opener = requests.sessions.session()
temp = opener.post(
url=url,
# headers=headers,
data=post_data)
print(temp.status_code, temp.reason)
print(temp.is_redirect)
print(temp.elapsed)
print(temp.headers.get('Location'))
输出:
200 OK
False
0:00:00.794888
None