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