我正在使用Keras
并尝试加载mnist
数据集。
该网站的链接是:https ://s3.amazonaws.com/img-datasets/mnist.pkl.gz
它在浏览器中工作。但是当我调用“mnist.load_data()”时,我得到了异常:
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:645)
已经提供了许多解决方案,我几乎尝试了所有解决方案。
下面是堆栈跟踪:
Downloading data from https://s3.amazonaws.com/img-datasets/mnist.pkl.gz
Traceback (most recent call last):
File "/home/user/anaconda3/lib/python3.5/urllib/request.py", line 1684, in open
return getattr(self, name)(url)
File "/home/user/anaconda3/lib/python3.5/urllib/request.py", line 1894, in open_https
return self._open_generic_http(self._https_connection, url, data)
File "/home/user/anaconda3/lib/python3.5/urllib/request.py", line 1843, in _open_generic_http
http_conn.request("GET", selector, headers=headers)
File "/home/user/anaconda3/lib/python3.5/http/client.py", line 1083, in request
self._send_request(method, url, body, headers)
File "/home/user/anaconda3/lib/python3.5/http/client.py", line 1128, in _send_request
self.endheaders(body)
File "/home/user/anaconda3/lib/python3.5/http/client.py", line 1079, in endheaders
self._send_output(message_body)
File "/home/user/anaconda3/lib/python3.5/http/client.py", line 911, in _send_output
self.send(msg)
File "/home/user/anaconda3/lib/python3.5/http/client.py", line 854, in send
self.connect()
File "/home/user/anaconda3/lib/python3.5/http/client.py", line 1237, in connect
server_hostname=server_hostname)
File "/home/user/anaconda3/lib/python3.5/ssl.py", line 376, in wrap_socket
_context=self)
File "/home/user/anaconda3/lib/python3.5/ssl.py", line 747, in __init__
self.do_handshake()
File "/home/user/anaconda3/lib/python3.5/ssl.py", line 983, in do_handshake
self._sslobj.do_handshake()
File "/home/user/anaconda3/lib/python3.5/ssl.py", line 628, in do_handshake
self._sslobj.do_handshake()
我在控制台上的“openssl 版本”:
openssl version
OpenSSL 1.0.2e 3 Dec 2015
在 python 控制台中:
>>> import OpenSSL
>>> OpenSSL.__version__
'0.15.1'
>>> import ssl
>>> print (ssl.OPENSSL_VERSION)
OpenSSL 1.0.2e 3 Dec 2015
我正在使用 anaconda 附带的 Python 3.5
我还使用升级了 OpenSSL,conda install OpenSSL
但错误仍然存在。
我还尝试了一个补丁:
import ssl
from functools import wraps
def sslwrap(func):
@wraps(func)
def bar(*args, **kw):
kw['ssl_version'] = ssl.PROTOCOL_TLSv1
return func(*args, **kw)
return bar
ssl.wrap_socket = sslwrap(ssl.wrap_socket)
但仍然没有解决办法。我怎样才能摆脱这个错误?