Skip to content

Instantly share code, notes, and snippets.

@netoxico
Forked from michaelhelmick/fix.py
Created June 27, 2014 14:08
Show Gist options
  • Save netoxico/93d1462de67626c30629 to your computer and use it in GitHub Desktop.
Save netoxico/93d1462de67626c30629 to your computer and use it in GitHub Desktop.
import httplib
import ssl
import socket
import sys
import urllib2
class HTTPSConnectionV3(httplib.HTTPSConnection):
def __init__(self, *args, **kwargs):
httplib.HTTPSConnection.__init__(self, *args, **kwargs)
def connect(self):
sock = socket.create_connection((self.host, self.port), self.timeout)
if sys.version_info < (2, 6, 7):
if hasattr(self, '_tunnel_host'):
self.sock = sock
self._tunnel()
else:
if self._tunnel_host:
self.sock = sock
self._tunnel()
try:
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=ssl.PROTOCOL_SSLv3)
except ssl.SSLError:
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=ssl.PROTOCOL_SSLv23)
class HTTPSHandlerV3(urllib2.HTTPSHandler):
def https_open(self, req):
return self.do_open(HTTPSConnectionV3, req)
urllib2.install_opener(urllib2.build_opener(HTTPSHandlerV3()))
urllib2.urlopen("https://yoursecureurl.com/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment