我正在练习google-python课程。但是,我遇到了urllib的问题。这是简化的代码:
import urllib
url = 'http://www.google.com'
ufile=urllib.urlopen(url)
此代码实际上有效,但如果我将网址更改为其他网址,例如:
url = 'https://developers.google.com/edu/python/utilities#exceptions'
会引发错误:
IOError: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)
完整的错误信息如下:
Traceback (most recent call last):
File "practice2.py", line 4, in <module>
ufile=urllib.urlopen(url)
File "/home/jren/Canopy/appdata/canopy-1.6.2.3262.rh5-x86_64/lib/python2.7/urllib.py", line 87, in urlopen
return opener.open(url)
File "/home/jren/Canopy/appdata/canopy-1.6.2.3262.rh5-x86_64/lib/python2.7/urllib.py", line 213, in open
return getattr(self, name)(url)
File "/home/jren/Canopy/appdata/canopy-1.6.2.3262.rh5-x86_64/lib/python2.7/urllib.py", line 443, in open_https
h.endheaders(data)
File "/home/jren/Canopy/appdata/canopy-1.6.2.3262.rh5-x86_64/lib/python2.7/httplib.py", line 1049, in endheaders
self._send_output(message_body)
File "/home/jren/Canopy/appdata/canopy-1.6.2.3262.rh5-x86_64/lib/python2.7/httplib.py", line 893, in _send_output
self.send(msg)
File "/home/jren/Canopy/appdata/canopy-1.6.2.3262.rh5-x86_64/lib/python2.7/httplib.py", line 855, in send
self.connect()
File "/home/jren/Canopy/appdata/canopy-1.6.2.3262.rh5-x86_64/lib/python2.7/httplib.py", line 1274, in connect
server_hostname=server_hostname)
File "/home/jren/Canopy/appdata/canopy-1.6.2.3262.rh5-x86_64/lib/python2.7/ssl.py", line 352, in wrap_socket
_context=self)
File "/home/jren/Canopy/appdata/canopy-1.6.2.3262.rh5-x86_64/lib/python2.7/ssl.py", line 579, in __init__
self.do_handshake()
File "/home/jren/Canopy/appdata/canopy-1.6.2.3262.rh5-x86_64/lib/python2.7/ssl.py", line 808, in do_handshake
self._sslobj.do_handshake()
IOError: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)
非常感谢您阅读本文!
答案 0 :(得分:1)
Python对ssl currently than it has been before要严格得多。您可以暂时绕过 ssl验证。看看this post。当然,这可能不是永久的解决方案,但如果您无权配置developers.google.com证书,那么这可能是您可以做的最好的。
答案 1 :(得分:0)
1检查SSL版本
2确保套接字模块的底部支持SSL编译模式,即SSL编译器选项打开时。
3端口错误,检查