eduardo@camizao:/$ python2.7
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>> url1 = 'http://www.google.com'
>>> url2 = 'https://www.google.com'
>>> f = urllib.urlopen(url1)
>>> f = urllib.urlopen(url2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/urllib.py", line 87, in urlopen
return opener.open(url)
File "/usr/lib/python2.7/urllib.py", line 211, in open
return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py", line 355, in open_http
'got a bad status line', None)
IOError: ('http protocol error', 0, 'got a bad status line', None)
>>>
当我尝试使用 urllib 连接到 https 站点时,出现上述错误。代理设置正确。调试 python 代码时,我注意到在 urllib.py 中没有执行对 ssl 库的导入。因此,也不会执行 https 调用。任何人都可以帮助我吗?我必须使用 urllib,而不是 urllib2 或另一个。提前致谢。