【发布时间】:2011-08-02 23:29:09
【问题描述】:
我很熟悉应该将 HTTP_RPOXY 环境变量设置为代理地址。
一般 urllib 工作正常,问题是处理 urllib2。
>>> urllib2.urlopen("http://www.google.com").read()
返回
urllib2.URLError: <urlopen error [Errno 10061] No connection could be made because the target machine actively refused it>
或
urllib2.URLError: <urlopen error [Errno 11004] getaddrinfo failed>
额外信息:
urllib.urlopen(....) 工作正常!只是 urllib2 在耍花招……
我尝试了@Fenikso 的回答,但我现在收到了这个错误:
URLError: <urlopen error [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>
有什么想法吗?
【问题讨论】:
-
你能发布实际的完整示例代码吗?
-
@Fenikso: 这个
urllib2.urlopen("http://www.google.com").read() -
所以你在 HTTP_PROXY 环境变量中设置了代理服务器?您确定服务器接受连接吗?