Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: SSLError, bad handshake, Unexpected EOF

I have an issue with connecting to a specific site using Python requests and get this error:

HTTPSConnectionPool(host='XXXXXXXXX', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError("bad handshake: SysCallError(-1, 'Unexpected EOF')",),))

How can I work around this? (setting verify=False does not make a difference) I'm suspecting the server who's at fault here as it get an overall rating of F @ ssllabs when I run their test

I am fairly new with Python and requests

my code:

import requests
try:
    site = requests.get('https://XXXXXXXXXX', verify=True)
    print(site)
except requests.exceptions.RequestException as e:
    print(e)
    pass
like image 849
nebbul Avatar asked Nov 06 '17 17:11

nebbul


2 Answers

As mentioned in other question https://stackoverflow.com/a/36499718/1657819 this error may happen if you're under proxy, so disabling proxy may help

unset https_proxy
like image 137
The Godfather Avatar answered Oct 17 '22 23:10

The Godfather


Faced with the same error my troubles went away after doing pip install ndg-httpsclient. yum install python-ndg_httpsclient or apt-get install python-ndg-httpsclient (or apt-get install python3-ndg-httpsclient) probably works too.

like image 24
bryn Avatar answered Oct 17 '22 23:10

bryn