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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32115607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 11:02:51  来源:igfitidea点击:

Python 3.4 SSL error urlopen error EOF occurred in violation of protocol (_ssl.c:600)

pythonpython-3.xsslpython-3.4

提问by Don Mums

I use Arch Linux, python 3.4, openSSL 1.0.2d. When I make request to https://www.supercash.cz/I get this error. It doesn't matter if I use requests or build in urllib there is always the same error. SSL certificate for this site seams to be OK in Chrome browser.

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

I tried this but it only works in python2.7 Error - urlopen error [Errno 8] _ssl.c:504: EOF occurred in violation of protocol , help needed

我试过了,但它只适用于 python2.7 错误 - urlopen 错误 [Errno 8] _ssl.c:504: EOF 发生违反协议,需要帮助

This is result of ssl test https://www.ssllabs.com/ssltest/analyze.html?d=supercash.cz

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

采纳答案by Viktor Stískala

This is the same error as this one: Python Requests requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol

这与这个错误相同:Python Requests requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF发生违反协议

You'll have to use custom HTTPAdapteras stated here: https://stackoverflow.com/a/14146031/407580

您必须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]>

回答by philshem

One potential solution is described here

此处描述了一种潜在的解决方案

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

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

Using python3 and installing the combo (pyopenssl ndg-httpsclient pyasn1 urllib3) did the trick.

使用 python3 并安装组合(pyopenssl ndg-httpsclient pyasn1 urllib3)可以解决问题。

pip install pyopenssl ndg-httpsclient pyasn1 urllib3