Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HandShake Failure in python(_ssl.c:590)

When I execute the below line,

req = urllib2.Request(requestwithtoken) 
self.response = urllib2.urlopen(req,self.request).read()

I am getting the following exception:

SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)

The thing is I am able to get the token by pinging the service by using curl. During the process of retrieving the token, all the certificates were verified. In turn, by using the generated token, i am not able to connect to the service. I am getting the above error while trying. What could be the reason for that?

like image 654
Bharathi Kodeeswaran Avatar asked Nov 18 '15 11:11

Bharathi Kodeeswaran


People also ask

What causes SSL certificate errors Python?

What Causes an SSL Certificate_Verify_Failed Error? SSL certificate_verify_failed errors typically occur as a result of outdated Python default certificates or invalid root certificates. If you're a website owner and you're receiving this error, it could be because you're not using a valid SSL certificate.

What is 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.


1 Answers

I was having the same issue. It's probably because your remote server requests cipher that isn't supported by urllib2. I think there're two solutions possible:

  1. Enable your specific cipher in urllib. I think you can also enable all ciphers supported (see the very bottom of the page) but rather check which one you're using with curl as shown in the link above.

  2. Install requests with extra security packages using: pip install requests[security]. It's further discussed in this requests issue on github.

I did the second option and it worked for me.

like image 178
martin Avatar answered Oct 13 '22 10:10

martin