Last active
January 28, 2016 08:34
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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