ssl.SSLError和urllib.error.URLError解决方式

使用PyG下载数据集的时候出现以下问题

from torch_geometric.datasets import ShapeNet
dataset = ShapeNet(root='ShapeNet', categories='Airplane')
print(dataset[0])
>>>ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)
>>>urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)

原因出资网站的自签名证书

import ssl 
ssl._create_default_https_context = ssl._create_unverified_context

加上这段代码即可解决

URLError: "urlopen error [Errno 8] _ssl.c:503: EOF occurred in violation of protocol" 直接通过浏览器可以访问,昨天也是好使的,今天就不行了 代码: url="https://ipaddress/xxx/xxx/xxx" kw={'xxx':'xxx'} data = urllib.urlencode(kw) req = urllib2.Request(url,data) base64string = base64.encodestring('%s:%s' % ('xxx', 'xxx'))[:-1] #这里最后会自动添加一个\n authheader = "Basic %s" % base64string req.add_header("Authorization", authheader) return_data = urllib2.urlopen(req) #请求url data = return_data.read() #读取内容 print data 错误: Traceback (most recent call last): File "C:\Python27\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 323, in RunScript debugger.run(codeObject, __main__.__dict__, start_stepping=0) File "C:\Python27\Lib\site-packages\Pythonwin\pywin\debugger\__init__.py", line 60, in run _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) File "C:\Python27\Lib\site-packages\Pythonwin\pywin\debugger\debugger.py", line 655, in run exec cmd in globals, locals File "C:\Users\wzs\Desktop\get_resulte.py", line 2, in <module> import urllib File "C:\Python27\lib\urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 394, in open response = self._open(req, data) File "C:\Python27\lib\urllib2.py", line 412, in _open '_open', req) File "C:\Python27\lib\urllib2.py", line 372, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 1207, in https_open return self.do_open(httplib.HTTPSConnection, req) File "C:\Python27\lib\urllib2.py", line 1174, in do_open raise URLError(err) URLError:<urlopen error [Errno 8] _ssl.c:503: EOF occurred in violation of protocol>
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页