gpt4 book ai didi

sockets - sklearn.datasets fetch_olivetti_faces IOError : [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl. c:661)

转载 作者:行者123 更新时间:2023-12-01 23:04:16 25 4
gpt4 key购买 nike

我尝试使用 sklearn 中的 fetch_olivetti_faces 数据集,但由于某些原因,我无法解决此 IOError 如果您可以帮助我:

这是我运行的代码:

from sklearn import datasets
data = datasets.fetch_olivetti_faces()

这是我得到的 IOError:

IOError: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)

这是我得到的所有错误:

File "/anaconda3/lib/python2.7/site-packages/sklearn/datasets/olivetti_faces.py", line 120, in fetch_olivetti_faces
mat_path = _fetch_remote(FACES, dirname=data_home)

File "/anaconda3/lib/python2.7/site-packages/sklearn/datasets/base.py", line 874, in _fetch_remote
urlretrieve(remote.url, file_path)

File "/anaconda3/lib/python2.7/urllib.py", line 98, in urlretrieve
return opener.retrieve(url, filename, reporthook, data)

File "/anaconda3/lib/python2.7/urllib.py", line 245, in retrieve
fp = self.open(url, data)

File "/anaconda3/lib/python2.7/urllib.py", line 213, in open
return getattr(self, name)(url)

File "/anaconda3/lib/python2.7/urllib.py", line 443, in open_https
h.endheaders(data)

File "/anaconda3/lib/python2.7/httplib.py", line 1038, in endheaders
self._send_output(message_body)

File "/anaconda3/lib/python2.7/httplib.py", line 882, in _send_output
self.send(msg)

File "/anaconda3/lib/python2.7/httplib.py", line 844, in send
self.connect()

File "/anaconda3/lib/python2.7/httplib.py", line 1263, in connect
server_hostname=server_hostname)

File "/anaconda3/lib/python2.7/ssl.py", line 363, in wrap_socket
_context=self)

File "/anaconda3/lib/python2.7/ssl.py", line 611, in __init__
self.do_handshake()

File "/anaconda3/lib/python2.7/ssl.py", line 840, in do_handshake
self._sslobj.do_handshake()

IOError: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)

最佳答案

只需导入ssl包并通过以下行执行以下命令即可解决问题:

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

请注意,这会禁用证书验证,从而有效地关闭 SSL。此解决方案在开发环境中很好,但在面向公众的任何地方使用此解决方案之前,必须先整理好您的证书。

关于sockets - sklearn.datasets fetch_olivetti_faces IOError : [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl. c:661),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47734530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com