I'm using python 2.7 and I'd like to get the contents of a webpage that requires sslv3. Currently when I try to access the page I get the error SSL23_GET_SERVER_HELLO, and some searching on the web lead me to the following solution which fixes things in Python 3
urllib.request.install_opener(urllib.request.build_opener(urllib.request.HTTPSHandler(context=ssl.SSLContext(ssl.PROTOCOL_TLSv1))))
How can I get the same effect in python 2.7, as I can't seem to find the equivalent of the context argument for the HTTPSHandler class.
Since I was unable to do this using urllib2, I eventually gave in and moved to using the libCurl bindings like @Bruno had suggested in the comments to pastylegs answer.
I realize this response is a few years too late, but I also ran into the same problem, and didn't want to depend on libcurl being installed on a machine where I ran this. Hopefully, this will be useful to those who find this post in the future.
The problem is that
httplib.HTTPSConnection.connect
doesn't have a way to specify SSL context or version. You can overwrite this function before you hit the meat of your script for a quick solution.An important consideration is that this workaround, as discussed above, will not verify the validity of the server's certificate.
*Note: this alternate
connect()
function was copy/pasted from httplib.py, and simply modified to specify thessl_version
in thewrap_socket()
callSSL should be handled automatically as long as you have the SSL libraries installed on your server (i.e. you shouldn't have to specificially add it as a handler)
Also, note that
urllib
andurllib2
have been merged in python 3 so their approach is a little different