【问题标题】:Python 3.4 SSL error urlopen error EOF occurred in violation of protocol (_ssl.c:600)Python 3.4 SSL 错误 urlopen 错误 EOF 发生违反协议 (_ssl.c:600)
【发布时间】:2015-11-13 22:33:24
【问题描述】:

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


    【解决方案1】:

    这是和这个一样的错误:Python Requests requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol

    您必须使用自定义 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]>
    

    【讨论】:

    • 不适用于 openssl 1.0.0e-2ubuntu 和 python 3.2.2,站点 www.pca.org。
    【解决方案2】:

    此处描述了一种可能的解决方案

    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
    

    【讨论】:

      猜你喜欢
      • 2012-07-31
      • 1970-01-01
      • 2017-12-18
      • 1970-01-01
      • 1970-01-01
      • 2017-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多