Don*_*ums 4 python ssl python-3.x python-3.4
我使用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)>
Run Code Online (Sandbox Code Playgroud)
我试过这个,但它只适用于python2.7 错误 - urlopen错误[Errno 8] _ssl.c:504:EOF发生违反协议,需要帮助
这是ssl测试的结果https://www.ssllabs.com/ssltest/analyze.html?d=supercash.cz
这里描述了一种可能的解决方案
https://github.com/kennethreitz/requests/issues/3006#issuecomment-274058323
https://web.archive.org/web/20160705110216/https://github.com/kennethreitz/requests/issues/3006
使用 python3 并安装组合(pyopenssl ndg-httpsclient pyasn1 urllib3)就可以了。
pip install pyopenssl ndg-httpsclient pyasn1 urllib3
Run Code Online (Sandbox Code Playgroud)
这与此错误相同:Python请求requests.exceptions.SSLError:[Errno 8] _ssl.c:504:违反协议发生EOF
您必须使用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]>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18904 次 |
| 最近记录: |