Based on the proxy instance in the Python requests library

Source: Internet
Author: User
This article mainly introduces the requests based on the Python proxy instance, has a certain reference value, and now share to everyone, the need for friends can refer to

Directly on the code:

#request代理 (proxy) "" "1. Start the proxy server Heroku, which is equivalent to aliyun2. Start the SOCKS service on host 1080 Port 3. Forward the request to 1080 Port 4. Get the appropriate resources first install package PIP install ' REQUESTS[SOCKSV5] ' "" "Import requests# define a proxy server, all HTTP and HTTPS go SOCKS5 protocol, SOCK5 equivalent to the HTTP protocol, it is at the session layer # Take it to the 1080 port of this machine proxies={' http ': ' socks5://127.0.0.1:1080 ', ' https ': ' socks5:/127.0.0.1.1080 '}url= ' https:// www.facebook.com ' #下面这样访问是会报错, because there is no proxy server, direct access to a firewall Response=requests.get (url,timeout=10) response=requests.get (URL , proxies=proxies,timeout=10) Print Response.status_code

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.