Python 3.4 SSL错误urlopen错误EOF发生违反协议(_ssl.c:600)

问题描述 投票:4回答:2

我使用Arch Linux,python 3.4,openSSL 1.0.2d。当我向https://www.supercash.cz/提出请求时,我收到此错误。如果我使用请求或构建urllib并不重要,则始终存在相同的错误。此网站的SSL证书在Chrome浏览器中可以正常使用。

File "/usr/lib64/python3.4/urllib/request.py", line 463, in open
    response = self._open(req, data)
File "/usr/lib64/python3.4/urllib/request.py", line 481, in _open
    '_open', req)
File "/usr/lib64/python3.4/urllib/request.py", line 441, in _call_chain
    result = func(*args)
File "/usr/lib64/python3.4/urllib/request.py", line 1225, in https_open
    context=self._context, check_hostname=self._check_hostname)
File "/usr/lib64/python3.4/urllib/request.py", line 1184, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:600)>

我试过这个,但它只适用于python2.7 Error - urlopen error [Errno 8] _ssl.c:504: EOF occurred in violation of protocol , help needed

这是ssl测试https://www.ssllabs.com/ssltest/analyze.html?d=supercash.cz的结果

python python-3.x ssl python-3.4
2个回答
6
投票

这与此错误相同:Python Requests requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol

你必须使用这里所述的自定义HTTPAdapterhttps://stackoverflow.com/a/14146031/407580

>>> import requests
>>> from requests.adapters import HTTPAdapter
>>> from requests.packages.urllib3.poolmanager import PoolManager
>>> import ssl
>>>
>>> class MyAdapter(HTTPAdapter):
...     def init_poolmanager(self, connections, maxsize, block=False):
...         self.poolmanager = PoolManager(num_pools=connections,
...                                        maxsize=maxsize,
...                                        block=block,
...                                        ssl_version=ssl.PROTOCOL_TLSv1)
...
>>> s = requests.Session()
>>> s.mount('https://', MyAdapter())
>>> s.get('https://www.supercash.cz')
<Response [200]>

1
投票

这里描述了一种可能的解决方案

https://github.com/kennethreitz/requests/issues/3006#issuecomment-274058323

使用python3并安装组合(pyopenssl ndg-httpsclient pyasn1 urllib3)就可以了。

pip install pyopenssl ndg-httpsclient pyasn1 urllib3
© www.soinside.com 2019 - 2024. All rights reserved.