Python urllib2 >HTTP代理>HTTPS 请求 [英] Python urllib2 > HTTP Proxy > HTTPS request
本文介绍了Python urllib2 >HTTP代理>HTTPS 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个工作正常:
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:
But, if http change to https:
...
print urllib2.urlopen('https://www.google.com').read()
存在错误:
Traceback (most recent call last):
File "D:Temp6 mp.py", line 13, in <module>
print urllib2.urlopen('https://www.google.com').read()
File "C:Python26liburllib2.py", line 124, in urlopen
return _opener.open(url, data, timeout)
File "C:Python26liburllib2.py", line 389, in open
response = self._open(req, data)
File "C:Python26liburllib2.py", line 407, in _open
'_open', req)
File "C:Python26liburllib2.py", line 367, in _call_chain
result = func(*args)
File "C:Python26liburllib2.py", line 1154, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "C:Python26liburllib2.py", line 1121, in do_open
raise URLError(err)
URLError: <urlopen error [Errno 10060]
为什么以及如何解决这个问题?
Why and how solve this problem?
推荐答案
更改这一行:
urllib2.ProxyHandler({'http': 'http://user:pass@proxy:3128'}))
为此:
urllib2.ProxyHandler({'https': 'http://user:pass@proxy:3128'}))
它对我来说很好.
这篇关于Python urllib2 >HTTP代理>HTTPS 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文