这项工作做得很好:
import urllib2
opener = urllib2.build_opener(
urllib2.HTTPHandler(),
urllib2.HTTPSHandler(),
urllib2.ProxyHandler({'http': 'http://user:pass@proxy:3128'}))
urllib2.install_opener(opener)
print urllib2.urlopen('http://www.google.com').read()但是,如果http更改为https
...
print urllib2.urlopen('https://www.google.com').read()有一些错误:
Traceback (most recent call last):
File "D:\Temp\6\tmp.py", line 13, in <module>
print urllib2.urlopen('https://www.google.com').read()
File "C:\Python26\lib\urllib2.py", line 124, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python26\lib\urllib2.py", line 389, in open
response = self._open(req, data)
File "C:\Python26\lib\urllib2.py", line 407, in _open
'_open', req)
File "C:\Python26\lib\urllib2.py", line 367, in _call_chain
result = func(*args)
File "C:\Python26\lib\urllib2.py", line 1154, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "C:\Python26\lib\urllib2.py", line 1121, in do_open
raise URLError(err)
URLError: <urlopen error [Errno 10060]为什么以及如何解决这个问题?
发布于 2010-07-14 17:43:05
更改这一行:
urllib2.ProxyHandler({'http': 'http://user:pass@proxy:3128'}))对此:
urllib2.ProxyHandler({'https': 'http://user:pass@proxy:3128'}))对我来说很好。
发布于 2010-05-28 09:32:40
在Windows上,errno 10060是一个winsock错误,意味着连接超时。您能使用代理设置为https://www.google.com的web浏览器从同一台机器到达http://user:pass@proxy:3128吗?您确定您的代理服务器可以同时处理同一个端口上的https和http吗?
发布于 2013-10-18 18:50:31
文档 for urllib2说:
注意:目前,urllib2不支持通过代理获取https位置。但是,可以通过扩展urllib2来启用这一点,如这个食谱中所示。
我必须承认,上面的配方对Jython2.5.3没有立即起作用,但我仍然在尝试。
UPDATE:我将这个补丁应用于Jython2.5.3,它为我工作。我现在可以通过代理服务器获取HTTPS资源。
UPDATE2:下面是使用HTTPS的基本身份验证来查询HTTPS资源的代码(不要忘记先安装修补程序(参见前面的更新)):
from suds.client import Client
from suds.transport.https import HttpAuthenticated
credentials = dict(username='...', password='...', proxy={'https': 'host:port', 'http': 'host:port'})
t = HttpAuthenticated(**credentials)
url = 'https://example.com/service?wsdl'
client = Client(url, transport=t)
print client.service.getFoo()https://stackoverflow.com/questions/2927831
复制相似问题