{"id":1005,"hash":"ab69d394439492fdf6642280bb6052b644fcee9b8434a95188f7e8b50095e46e","pattern":"Python Requests requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol","full_message":"I'm on Ubuntu 12.10 with OpenSSL 1.0.1c, python 2.7.3, Requests 1.0.3 and 1.0.4 (tried both), and when attempting to connect to the website in the url variable with the following code.\n\ndef SendInitialRequest(xmlmessage, redirecturl):\n    url = 'https://centineltest.cardinalcommerce.com/maps/txns.asp'\n\n    payload = 'cmpi_msg=' + ET.tostring(xmlmessage)\n    headers = {\n        'Content-Type': 'application/x-www-form-urlencoded',\n    }\n    r = requests.post(url, data=payload, headers=headers, verify=None)\n    print r.text\n\nIt throws the following error:\n\nTraceback (most recent call last):\n  File \"<stdin>\", line 1, in <module>\n  File \"clams/libs/centinel/thinclient.py\", line 134, in SendInitialRequest\n    r = requests.post(url, data=payload, headers=headers, verify=None)\n  File \"/home/jasonamyers/.virtualenv/clams/lib/python2.7/site-packages/requests/api.py\", line 87, in post\n    return request('post', url, data=data, **kwargs)\n  File \"/home/jasonamyers/.virtualenv/clams/lib/python2.7/site-packages/requests/api.py\", line 44, in request\n    return session.request(method=method, url=url, **kwargs)\n  File \"/home/jasonamyers/.virtualenv/clams/lib/python2.7/site-packages/requests/sessions.py\", line 269, in request\n    resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)\n  File \"/home/jasonamyers/.virtualenv/clams/lib/python2.7/site-packages/requests/sessions.py\", line 364, in send\n    r = adapter.send(request, **kwargs)\n  File \"/home/jasonamyers/.virtualenv/clams/lib/python2.7/site-packages/requests/adapters.py\", line 163, in send\n    raise SSLError(e)\nrequests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol\n\nAttempting the connection with openssl returns the following:\n\n$ openssl s_client -connect centineltest.cardinalcommerce.com:443\nCONNECTED(00000003)\n140019346777760:error:140790E5:SSL routines:SSL23_WRITE:ssl handshake failure:s23_lib.c:177:\n---\nno peer certificate available\n---\nNo client certificate CA names sent\n---\nSSL handshake has read 0 bytes and written 226 bytes\n---\nNew, (NONE), Cipher is (NONE)\nSecure Renegotiation IS NOT supported\nCompression: NONE\nExpansion: NONE\n---\n\nIf I force it to use tls1 it works (output truncated):\n\n$ openssl s_client -tls1 -connect centineltest.cardinalcommerce.com:443\nCONNECTED(00000003)\ndepth=2 C = US, O = \"thawte, Inc.\", OU = Certification Services Division, OU\nverify error:num=20:unable to get local issuer certificate\nverify return:0\n---\n\nI've seen numerous bug reports for this; however, I've not found a way to get around it using the python requests library.  Any assistance would be greatly appreciated.","ecosystem":"pypi","package_name":"openssl","package_version":null,"solution":"Reposting this here for others from the requests issue page:\n\nRequests' does not support doing this before version 1. Subsequent to version 1, you are expected to subclass the HTTPAdapter, like so:\n\nfrom requests.adapters import HTTPAdapter\nfrom requests.packages.urllib3.poolmanager import PoolManager\nimport ssl\n\nclass MyAdapter(HTTPAdapter):\n    def init_poolmanager(self, connections, maxsize, block=False):\n        self.poolmanager = PoolManager(num_pools=connections,\n                                       maxsize=maxsize,\n                                       block=block,\n                                       ssl_version=ssl.PROTOCOL_TLSv1)\n\nWhen you've done that, you can do this:\n\nimport requests\ns = requests.Session()\ns.mount('https://', MyAdapter())\n\nAny request through that session object will then use TLSv1.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/14102416/python-requests-requests-exceptions-sslerror-errno-8-ssl-c504-eof-occurred","votes":68,"created_at":"2026-04-19T04:52:09.117002+00:00","updated_at":"2026-04-19T04:52:09.117002+00:00"}