Kumar Nitin
Kumar Nitin

Reputation: 1863

SSLError: sslv3 alert handshake failure

I'm making the following call to branch.io

import requests
req = requests.get('https://bnc.lt/m/H3XKyKB3Tq', verify=False)

It works fine in my local machine but fails in the server.

SSLError: [Errno 1] _ssl.c:504: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

Openssl versions:

local: OpenSSL 0.9.8zg 14 July 2015

server: OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008

Python:

local: 2.7.10 server: 2.7.6

Branch io server connection:

Chrome verified that DigiCert SHA2 Secure Server CA issued this website's certificate. The server did not supply any Certificate Transparency information.

I tried urllib2, but the result was same. Any help?

Upvotes: 36

Views: 93475

Answers (2)

Saiyam Jain
Saiyam Jain

Reputation: 161

for those who are working on python 3.9 and you are facing this issue "SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] " while getting certificate or fetching expiry date for particular url

so you have to follow this steps in order to get valid response from the url

  1. install openssl in windows
  2. now copy the folder path of openssl which is being installed in C drive

use below code

servers is list of url and ports is list of all ports in my case

for i in range(0,len(servers)):
    try:
        s = servers[i]
        port = ports[i]
        print("querying {}".format(s))
        q = Popen(["C:\\Program Files\\OpenSSL-Win64\\bin\\openssl.exe", "s_client", "-connect","{}:{}".format(s,port),"-servername",s,"-showcerts" ], stdout=PIPE, stdin=PIPE, shell=False)
        y = check_output(["C:\\Program Files\\OpenSSL-Win64\\bin\\openssl.exe", "x509", "-noout", "-dates"], stdin=q.stdout)
        print(y.decode("utf-8"))
    except Exception as e:
        print(e) 

Upvotes: 2

Rahul
Rahul

Reputation: 1021

Jyo de Lys has identified the problem. The problem is described here and the solution is here. I did the following to get this working:

  1. easy_install pyOpenSSL
  2. easy_install ndg-httpsclient
  3. easy_install pyasn1

If you're getting this error while using urllib2, you'll need to upgrade to python 2.7.9 or later too.

Upvotes: 43

Related Questions