【发布时间】:2015-06-16 04:45:10
【问题描述】:
我是 Python 新手,我一直在尝试获取页面的源代码,并在 Python 2 和 3 上尝试了几种方法(这里是一个)
import urllib
url = "https://www.google.ca/?gfe_rd=cr&ei=u6d_VbzoMaei8wfE1oHgBw&gws_rd=ssl#q=test"
f = urllib.urlopen(url)
source = f.read()
print source
但我不断收到以下错误:
Traceback (most recent call last):
File "C:\Python34\openpage.py", line 4, in <module>
f = urllib.urlopen(url)
File "C:\Python27\lib\urllib.py", line 87, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 213, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 443, in open_https
h.endheaders(data)
File "C:\Python27\lib\httplib.py", line 1049, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 893, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 855, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 1274, in connect
server_hostname=server_hostname)
File "C:\Python27\lib\ssl.py", line 352, in wrap_socket
_context=self)
File "C:\Python27\lib\ssl.py", line 579, in __init__
self.do_handshake()
File "C:\Python27\lib\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)
最后一行表明错误来自安全搜索,但我似乎找不到解决方法。
我查看了this 的帖子,但仍然没有成功。
【问题讨论】:
-
您的系统上是否有有效的 cacerts,并且您的系统一般可以使用 SSL 吗?
curl说什么?