-
-
Save michaeldorner/5351a42e75f2c42c6918 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http.client | |
import ssl | |
import socket | |
import sys | |
import urllib | |
class HTTPSConnectionV3(http.client.HTTPSConnection): | |
def __init__(self, *args, **kwargs): | |
http.client.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(urllib.request.HTTPSHandler): | |
def https_open(self, req): | |
return self.do_open(HTTPSConnectionV3, req) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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