Skip to content

Instantly share code, notes, and snippets.

@Kasahs
Last active January 28, 2016 08:34
Show Gist options
  • Save Kasahs/ca2322477ca58e9d009c to your computer and use it in GitHub Desktop.
Save Kasahs/ca2322477ca58e9d009c to your computer and use it in GitHub Desktop.
To solve 'EOF occurred in violation of protocol' error when using the python requests module
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
import ssl
class MyAdapter(HTTPAdapter):
"""Create http adapter that uses TLSv1 protocol."""
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(num_pools=connections,
maxsize=maxsize,
block=block,
ssl_version=ssl.PROTOCOL_TLSv1)
# usage
s = requests.Session()
s.mount('https://', MyAdapter())
res = s.request('GET', url, headers=headers)
# do stuff with response
# read
# http://stackoverflow.com/questions/14102416/python-requests-requests-exceptions-sslerror-errno-8-ssl-c504-eof-occurred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment