Python 3.5 - ssl.SSLEOFError:EOF违反协议(_ssl.c:645)

时间:2016-01-19 08:46:53

标签: python-3.x ssl openssl anaconda keras

我正在使用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)

已经提供了很多解决方案,我几乎尝试了所有解决方案。

下面是stacktrace:

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

我还使用conda install OpenSSL升级了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)

但仍然没有解决方案。我怎样才能摆脱这个错误?

0 个答案:

没有答案