Environment Python 2.7python proxy type selection python proxy settings are usually as follows:
= { "http""http://10.10.1.10:3128", "https""http://10.10.1.10:1080",}
In HTTP and HTTPS two types, the HTTPS type of IP must correspond to such as: "https": "https ...", such as: "http": "https ..." this setting is wrong.
Test code example, the main following 4 kinds of situations: 1.requests Library Agent code into the following:
import= {"http""http://122.114.31.177:808"} # 1. 成功= {"http""https://110.73.50.236:8123"# 2. 失败= {"https""http://122.114.31.177:808"} # 3. 成功= {"https""https://110.73.50.236:8123"# 4. 失败= requests.get("http://www.baidu.com", proxies=proxies)print# 检测响应
The 2.urllib library Proxy code is as follows:
import= {"http""http://122.114.31.177:808"} # 1. 成功= {"http""https://110.73.50.236:8123"# 2. 失败= {"https""http://122.114.31.177:808"} # 3. 成功= {"https""https://110.73.50.236:8123"# 4. 失败= urllib.urlopen("http://www.baidu.com",proxies=proxies)print# 检测响应
Summarize
In order to avoid errors, we usually only need to set the HTTPS proxy type at the beginning, so that HTTP and HTTP types of IP can be proxied successfully.
Python Proxy type description