我使用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 test https://www.ssllabs.com/ssltest/analyze.html?d=supercash.cz
的结果答案 0 :(得分:6)
您必须使用此处所述的自定义HTTPAdapter
:https://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 :(得分:0)
这里描述了一种可能的解决方案
https://github.com/kennethreitz/requests/issues/3006#issuecomment-274058323
使用python3并安装组合(pyopenssl ndg-httpsclient pyasn1 urllib3)可以达到目的。
pip install pyopenssl ndg-httpsclient pyasn1 urllib3