Workaround for 302 redirection problem when using requests in Python

Source: Internet
Author: User
Using the requests analog login, the direct use of the Request.get (URL), easy to cause 302 Redirect, the reason is because the cookie is not durable (requests with cookie processing, but not durable),

The solution is to use the request. Session () object to persist the state of the cookie.

For example:

s = requests. Session () response = S.get (URL, headers=headers)  #其他操作

In addition, a 302 redirect occurs when a Session object is used to request a page without passing in the corresponding request header (for example: Referer), which causes the server to verify that it does not pass and returns

REDIRECT Messages. The solution is to build the corresponding request header and get the page to pass in.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.