【发布时间】:2020-06-18 00:28:16
【问题描述】:
我正在尝试登录基于 cloudflare 服务器的网站。我使用 cloudserver 绕过了登录问题,但我的下一站是当我尝试发送获取请求以访问某些登录后令牌时。
我的代码:
headers = {
'authority': 'www.paf.es',
'accept': 'application/json, text/plain, */*',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36',
'x-requested-with': 'XMLHttpRequest',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://www.paf.es/my-paf',
'accept-language': 'es-ES,es;q=0.9,en;q=0.8',
'cookie': '__cfduid=d4247b3fce5d260d7c5257b5d65a572001592254859; com.paf.frontend.common.LocaleCookie=es_ES; _gcl_au=1.1.193127229.1592254863; _ga=GA1.2.484179826.1592254863; _gid=GA1.2.1016568931.1592254863; _fbp=fb.1.1592254863595.468566668; com.paf.frontend.cookiesAccepted=true; com.paf.frontend.common.device=desktop; __cf_bm=10366cb3cb936cf0d9188cdf37dfaf276961f164-1592257614-1800-AbXayDicXL3zBDecjcoUuzlv+Qb5YhjhhqZO6goD80+W/J7ahYM+mwNHdcav405NnNOcPxyErOcdvPzijcdXGhk=; BIGipServerprod01_pool=1067697930.22811.0000; _gat_UA-641842-15=1; com.paf.frontend.common.showMenu=account; _gali=loginButton; JSESSIONID=tuO580BlkBaMw5v3txOBy0v2hqQV-61ZBQCVRqdqcTEQN4-5Z6tuu0021151447412; com.paf.frontend.common.LoginTime=1592257626364; com.paf.frontend.common.LoggedIn=true; __cfruid=5fe9d18ceeda0612668c20982f65d634686cb526-1592227626; com.paf.frontend.common.LifeCycleCookie=HAS_LOGGED_IN; trackingParams={"_ga":{"value":"GA1.2.484179826.1592254863","expiration":1600033627916},"utm_nooverride":{"value":"1","expiration":1600033627916}}; com.paf.frontend.common.LocaleCookie=es_ES; JSESSIONID=m4650rp-X0aJYw_6b8-3ghQIOU-h1luYOQV4dAwZz6UGVc4RanvZ!151447412; com.paf.frontend.common.LoginTime=1592255494930; com.paf.frontend.common.LoggedIn=true; __cfruid=3ffb40834f313a4c2b4d351r24f9a946uu5f7db9-1592255495'
}
cloudserver.get(url=url,headers=headers,data=json.dumps({}))
这会返回 401 作为答案:
The request requires user authentication. The response MUST include a WWW-Authenticate header field (section 14.46) containing a challenge applicable to the requested resource. The client MAY repeat the request with a suitable Authorization header field (section 14.8). If the request already included Authorization credentials, then the 401 response indicates that authorization has been refused for those credentials. If the 401 response contains the same challenge as the prior response, and the user agent has already attempted authentication at least once, then the user SHOULD be presented the entity that was given in the response, since that entity MAY include relevant diagnostic information.
它的标题是
{'Date': 'Wed, 17 Jun 2020 23:56:04 GMT', 'Content-Type': 'text/html; charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'CF-Ray': '5a50b4816fddd665-MAD', 'Set-Cookie': 'com.paf.frontend.common.LocaleCookie=es_ES; expires=Thu, 17-Jun-2021 23:56:04 GMT; path=/, com.paf.frontend.common.LoggedIn=; expires=Thu, 01-Jan-1970 01:00:00 GMT; path=/, __cf_bm=73f0a2b2216d419f8a19f3e8ff74e8eca2458229-1592438164-1800-AaPuIPRQVOJGvI9l1DBiMeXXmyczqpm7Owaf2XUHFqZ+FJ9PT44TdL4kxAU4FCOWDWQmztz9Ff1FTHrCcDQw88w=; path=/; expires=Thu, 18-Jun-20 00:26:04 GMT; domain=.paf.es; HttpOnly; Secure; SameSite=None', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains; preload', 'CF-Cache-Status': 'DYNAMIC', 'cf-request-id': '03664f24e50000d66506af8200000001', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'X-Content-Type-Options': 'nosniff', 'Vary': 'Accept-Encoding', 'Server': 'cloudflare', 'alt-svc': 'h3-27=":443"; ma=86400'}
好的,所以我首先尝试提供身份验证。像这样
s.get(url=url,headers=headers,data=json.dumps({}),auth=HTTPBasicAuth('somemail@mail.com','password'))
我再次遇到同样的错误,即 401,但这次响应的标头确实有一个 www-authenticate 我应该挑战
{'Date': 'Wed, 17 Jun 2020 23:58:42 GMT', 'Content-Type': 'text/html; charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'CF-Ray': '5a50b85dd8fdd665-MAD', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains; preload', 'WWW-Authenticate': 'Basic realm="weblogic"', 'CF-Cache-Status': 'DYNAMIC', 'cf-request-id': '0366518ea80000d66506a1b200000001', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'X-Content-Type-Options': 'nosniff', 'Set-Cookie': '__cf_bm=c153a7277cf7abbaa004cdb46da821906f04b7c6-1592438322-1800-AR+KhjkQM5NHTTqKA0scqXrUGJpKNOnG0ZASOG386zEILi28YAh28BV+pWYGXzly+7ptsr9TJSGurY2nBOTv75I=; path=/; expires=Thu, 18-Jun-20 00:28:42 GMT; domain=.paf.es; HttpOnly; Secure; SameSite=None', 'Vary': 'Accept-Encoding', 'Server': 'cloudflare', 'alt-svc': 'h3-27=":443"; ma=86400'}
根据我的阅读,它是基本的意味着我必须在我的标题中添加一个像 'Authentication': "Basic fhsejdjsjejdsj" 这样的键,它是基本之后的字符串,是 'username:password' 的 base64 编码。
但是,在我的标头中添加此内容后,我再次发送了一个请求,但我仍然停留在同一点,使用相同的 401。
我的问题是,在“WWW-Authenticate”中:“Basic realm="weblogic"” 域之后的内容是否重要?我怎样才能克服这个问题并能够完成我的请求?
【问题讨论】:
-
为什么不使用 requests.get 呢?
-
我不明白,而不是什么
-
使用requests lib,可以google python requests lib使用
-
cloudserver 是一个基于请求的库。它用于绕过 cloudflare 给请求的 403。如果您对此获取查询使用常规请求,您仍然会得到 401
-
您是否尝试过在 Postman 中运行您的 get 请求?这个问题看起来像是标题(与 Python 代码相关)。同样在你的标题中你有身份验证,但我认为正确的词是授权,例如:“授权”:“基本 abcde”
标签: python-3.x authentication python-requests http-status-code-401