Tensorflow 中的 Python SSL 认证问题

jmk*_*may 6 python ssl download mnist tensorflow

我正在尝试下载据称在以下位置处理的 MNIST 数据:

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

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

我不断收到此回溯错误:

文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py”,第 1318 行,在 do_open encode_chunked=req.has_header('Transfer-encoding')) 文件“/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”,第 1285 行,在 _send_request self.endheaders(body, encode_chunked=encode_chunked) 文件“/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/客户端。py”,第 1026 行,在 _send_output self.send(msg) 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第 964 行,在发送 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) 文件"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl .py”,第 808 行,在/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect server_hostname=server_hostname) 文件 "/Library/Frameworks/Python.framework/Versions/3.6/ lib/python3.6/ssl.py", line 401, in wrap_socket _context=self, _session=session) 文件 "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py",第 808 行,在/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect server_hostname=server_hostname) 文件 "/Library/Frameworks/Python.framework/Versions/3.6/ lib/python3.6/ssl.py", line 401, in wrap_socket _context=self, _session=session) 文件 "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py",第 808 行,在init self.do_handshake() 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py”,第 1061 行,在 do_handshake self._sslobj.do_handshake() 文件“/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] 证书验证失败 (_ssl.c:748 )

它显然与 python 使用的 SSL 证书有关......所以我去了 /Applications/Python 3.6/ 并执行了位于那里的“Install Certifactions.command”并得到了这个错误:

回溯(最近一次调用):文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shutil.py”,第 544 行,移动 os.rename(src, real_dst) PermissionError: [ Errno 13] 权限被拒绝:'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/certifi-2015.04.28.dist-info/DESCRIPTION.rst' -> '/var/文件夹/mq/g_jy_1qx1vjdb3xmdh7y62y80000gn/T/pip-3m8ixnf5-uninstall/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/certifi-2015.04-IPTION.2rs'tinfo

在处理上述异常的过程中,又发生了一个异常:

回溯(最近一次调用):文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/basecommand.py”,第 215 行,主状态 = self.run (options, args) 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/commands/install.py”,第 342 行,在运行 prefix=options.prefix_path 中,文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/req/req_set.py”,第778行,安装requirements.uninstall(auto_confirm=True)文件“/ Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/req/req_install.py”,第 754 行,卸载路径中的 path_to_remove.remove(auto_confirm) 文件“/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 /点子/工具/init .py”,第 267 行,在重命名 Shutil.move(old, new) 文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shutil.py”,第 559 行,在移动操作系统中.unlink(src) PermissionError: [Errno 13] 权限被拒绝: '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/certifi-2015.04.28.dist-info/DESCRIPTION。第一'

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

有没有办法手动安装证书?或者发出 pull request 将数据下载到非 https 地址?

mig*_*rin 7

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

/Applications/Python\ 3.6/Install\ Certificates.command
Run Code Online (Sandbox Code Playgroud)

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

来源:TensorFlow GitHub 上的官方模型专用问题


小智 3

将 https 替换为 http 即可运行

在 contrib/learn/python/learn/datasets/mnist.py 中编辑 SOURCE_URL=' http://storage.googleapis.com/cvdf-datasets/mnist/ '行