【发布时间】:2020-01-03 20:05:36
【问题描述】:
我正在尝试登录,但出现 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()
【问题讨论】:
-
发布代码而不是您的代码图片,还有谁支持这个?
-
首先您应该指定您正在使用的 Web 框架或 Web 服务器。 Python 本身是一种多用途语言,没有 Web 功能。它们都是由图书馆提供的。
-
我建议让
requests为您编码您的数据,而不是尝试手动完成。 -
@Sahil 我已经调整过了。
-
@DavidMoseler 请解释更多。我应该添加或调整什么?
标签: python python-3.x https request http-status-code-404