Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python requests ssl handshake failure

Every time I try to do:

requests.get('https://url')  

I got this message:

import requests >>> requests.get('https://reviews.gethuman.com/companies')  Traceback (most recent call last):     File "<stdin>", line 1, in <module>     File "/usr/lib/python2.7/dist-packages/requests/api.py", line 55, in get      return request('get', url, **kwargs)     File "/usr/lib/python2.7/dist-packages/requests/api.py", line 44, in request      return session.request(method=method, url=url, **kwargs)        File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 455, in request      resp = self.send(prep, **send_kwargs)     File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 558, in send      r = adapter.send(request, **kwargs)     File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 385, in send      raise SSLError(e) requests.exceptions.SSLError: [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure 

I tried everything:

  • update my requests
  • update my ssl

but nothing changes.

I am using Python 2.7.6, can't change this.

like image 464
Idan Haim Shalom Avatar asked Jul 27 '15 09:07

Idan Haim Shalom


People also ask

How do I skip SSL verification in Python?

Python3. Explanation: By passing verify=False to the request method we disabled the security certificate check and made the program error-free to execute.

Why does SSL handshake failed?

A TLS/SSL handshake failure occurs when a client and server cannot establish communication using the TLS/SSL protocol. When this error occurs in Apigee Edge, the client application receives an HTTP status 503 with the message Service Unavailable.


2 Answers

On OSX, using python 2.7.10 / requests 2.9.1 I only had to to install requestsusing its security setup:

pip install requests[security] 

This installs pyOpenSSL, ndg-httpsclient and pyasn1. https://github.com/kennethreitz/requests/blob/master/setup.py#L70

like image 107
Tobias Lorenz Avatar answered Sep 22 '22 19:09

Tobias Lorenz


I resolve the problem in the end i updated my ubuntu from 14.04 to 14.10 and the problem was solved

but in the older version of ubuntu and python I install those lib and it seems to fix all my problems

sudo apt-get install python-dev libssl-dev libffi-dev sudo pip2.7 install -U pyopenssl==0.13.1 pyasn1 ndg-httpsclient 

if you don`t have pip2.7 installed you can use pip instead

like image 26
Idan Haim Shalom Avatar answered Sep 20 '22 19:09

Idan Haim Shalom