HandShake Failure in python(_ssl.c:590)

2019-02-12 02:03发布

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?

2条回答
你好瞎i
2楼-- · 2019-02-12 02:27

I also had the same issue. Check which version of requests you are using.

import requests
print requests.__version__

If the version is 2.18.4, you should try downgrading to version 2.11.1. I did this, and it fixed my problem. To do this, issue the following commands in the terminal

pip uninstall requests
pip install requests==2.11.1 

Hope this helps.

查看更多
何必那么认真
3楼-- · 2019-02-12 02:34

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.

查看更多
登录 后发表回答