From 386284693d7d50bf0179fabe2a677f2e85ecedae Mon Sep 17 00:00:00 2001 From: j Date: Fri, 24 Jun 2016 14:32:20 +0200 Subject: [PATCH] use _create_stdlib_context if _create_default_https_context does not exist --- oml/tor_request.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/oml/tor_request.py b/oml/tor_request.py index a9ae455..c9aa609 100644 --- a/oml/tor_request.py +++ b/oml/tor_request.py @@ -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)