天天看點

URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:590)>

問題

使用python,配合requests或urllib2進行get某網址時,報錯

URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:)>
           

解決辦法

>>> 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 []>
           

參考

https://stackoverflow.com/questions/32115607/python-3-4-ssl-error-urlopen-error-eof-occurred-in-violation-of-protocol-ssl-c

http://stackoverflow.com/a/14146031/407580