use _create_stdlib_context if _create_default_https_context does not exist
This commit is contained in:
parent
4fcad3bddf
commit
386284693d
1 changed files with 9 additions and 5 deletions
|
@ -67,11 +67,15 @@ class TorHTTPSConnection(http.client.HTTPSConnection):
|
|||
def __init__(self, host, port=None, service_id=None, check_hostname=None, context=None, **kwargs):
|
||||
self._service_id = service_id
|
||||
if self._service_id:
|
||||
context = ssl._create_default_https_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()
|
||||
if hasattr(ssl, '_create_default_https_context'):
|
||||
context = ssl._create_default_https_context()
|
||||
elif hasattr(ssl, '_create_stdlib_context'):
|
||||
context = ssl._create_stdlib_context()
|
||||
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,
|
||||
check_hostname=check_hostname, context=context, **kwargs)
|
||||
|
||||
|
|
Loading…
Reference in a new issue