use _create_stdlib_context if _create_default_https_context does not exist

This commit is contained in:
j 2016-06-24 14:32:20 +02:00
parent 4fcad3bddf
commit 386284693d

View file

@ -67,11 +67,15 @@ class TorHTTPSConnection(http.client.HTTPSConnection):
def __init__(self, host, port=None, service_id=None, check_hostname=None, context=None, **kwargs): def __init__(self, host, port=None, service_id=None, check_hostname=None, context=None, **kwargs):
self._service_id = service_id self._service_id = service_id
if self._service_id: if self._service_id:
context = ssl._create_default_https_context() if hasattr(ssl, '_create_default_https_context'):
context.check_hostname = False context = ssl._create_default_https_context()
context.verify_mode = ssl.CERT_NONE elif hasattr(ssl, '_create_stdlib_context'):
context.load_cert_chain(settings.ssl_cert_path, settings.ssl_key_path) context = ssl._create_stdlib_context()
context.load_default_certs() if context:
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
context.load_cert_chain(settings.ssl_cert_path, settings.ssl_key_path)
context.load_default_certs()
http.client.HTTPSConnection.__init__(self, host, port, http.client.HTTPSConnection.__init__(self, host, port,
check_hostname=check_hostname, context=context, **kwargs) check_hostname=check_hostname, context=context, **kwargs)