Python中Tensorflow的SSL证书问题

7

我正在尝试下载MNIST数据集,它应该在以下位置进行处理:

tensorflow.examples.tutorials.mnist.input_data.read_data_sets()

据我所知,read_data_sets会向服务器发送拉取请求以下载大约1.5GB的数据。

但是,我一直收到这个回溯错误:

File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)   File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)   File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
line 1026, in _send_output
    self.send(msg)   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
line 964, in send
    self.connect()   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
line 1400, in connect
    server_hostname=server_hostname)   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py",
line 401, in wrap_socket
    _context=self, _session=session)   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py",
line 808, in __init__
    self.do_handshake()   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py",
line 1061, in do_handshake
    self._sslobj.do_handshake()   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py",
line 683, in do_handshake
    self._sslobj.do_handshake() ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)

很明显这与Python使用的SSL证书有关...所以我进入了/Applications/Python 3.6/,并执行了位于那里的"Install Certifactions.command",结果出现了以下错误:

Traceback (most recent call last):   File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shutil.py",
line 544, in move
    os.rename(src, real_dst) PermissionError: [Errno 13] Permission denied:
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/certifi-2015.04.28.dist-info/DESCRIPTION.rst'
-'/var/folders/mq/g_jy_1qx1vjdb3xmdh7y62y80000gn/T/pip-3m8ixnf5-uninstall/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/certifi-2015.04.28.dist-info/DESCRIPTION.rst'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/basecommand.py",
line 215, in main
    status = self.run(options, args)   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/commands/install.py",
line 342, in run
    prefix=options.prefix_path,   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/req/req_set.py",
line 778, in install
    requirement.uninstall(auto_confirm=True)   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/req/req_install.py",
line 754, in uninstall
    paths_to_remove.remove(auto_confirm)   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/req/req_uninstall.py",
line 115, in remove
    renames(path, new_path)   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/utils/__init__.py",
line 267, in renames
    shutil.move(old, new)   File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shutil.py",
line 559, in move
    os.unlink(src) PermissionError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/certifi-2015.04.28.dist-info/DESCRIPTION.rst'

我的文件系统权限有问题吗?大约一个月前我在这台电脑上重新安装了OSX...

我能否手动安装证书?或者发出拉取请求,以从非https地址下载数据?


更新:我已经能够从Yann Lecun的网站手动下载文件并将它们放置在正确的目录中。程序现在可以工作了,但仍然希望找出问题的根源。 - jmkmay
2个回答

9

安装证书,可以在macOS上双击/Applications/Python 3.6/Install Certificates.command文件或从 终端运行以下命令:

/Applications/Python\ 3.6/Install\ Certificates.command

现在证书已安装,可以通过HTTPS下载数据。

来源:TensorFlow GitHub官方模型问题专区


3

当我这样做时,我仍然遇到了错误,但是当我编辑了这个文件:/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tensorflow/python/keras/datasets/fashion_mnist.py并且删除了https中的s后,它就可以工作了。 - ahitt6345
这个解决方案对我很有效。在虚拟环境的情况下,文件的位置是venv/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py - miguelmorin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接