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

吃可爱长大的小学妹 提交于 2019-12-01 19:21:16
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

You'll have to use custom HTTPAdapter as stated here: 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]>

One potential solution is described here

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

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

pip install pyopenssl ndg-httpsclient pyasn1 urllib3
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!