简体   繁体   English

如何正确使用 Python 请求?

[英]How to Use Python Requests Correctly?

In python I currently have the following code:在python中,我目前有以下代码:

s.cookies.clear()
s.post(page_url, data={'OP': 'LI', 'username': daniel, 'password': daniel123,
                       'g-recaptcha-response': user_answer['solution']['gRecaptchaResponse']})
time.sleep(1)
print(s.cookies)

When I run it I see many cookies being printed twice, why is that?当我运行它时,我看到许多 cookie 被打印两次,这是为什么?

You should use allow_redirects=True in the arguments.您应该在参数中使用allow_redirects=True

as that would take you to origin website instead of reading cookies off of a 302 response and trying to sleep on it.因为这会带你到原始网站,而不是从 302 响应中读取 cookie 并试图在它上面睡觉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM