Python的代理身份验证有没有人对为什么Urlib2版本返回网页的任何想法,而请求版本返回连接错误:与请求和Urlib2
[Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
urllib2的代码(工作):
import urllib2
proxy = urllib2.ProxyHandler({'http': 'http://login:[email protected]:80'})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
wPage = urllib2.urlopen('http://www.google.com/')
print wPage.read();
请求的代码(不工作 - errno的10060):
import requests
proxy = {"http": "http://login:[email protected]:80"}
wPage = requests.get('http://www.google.com/', proxies=proxy)
print wPage.text
请求版本返回内联网网页,但在网页上出现错误。
我正在运行的Python 2.7
*编辑*
基于m170897017的建议,我看着在GET请求的差异。唯一的区别是在连接和代理连接。
的urllib2版本:
header: Connection: close
header: Proxy-Connection: close
请求版本:
header: Connection: Keep-Alive
header: Proxy-Connection: Keep-Alive
我强迫请求版本通过修改标头
header = {
"Connection": "close",
"Proxy-Connection": "close"
}
为GET请求,关闭两个那些连接两者现在都匹配,但Requests版本仍然不起作用。
嗅包,看看HTTP GET是不同的。 –