Don't use pyOpenSSL unless no SNI is detected

This commit is contained in:
Seth Michael Larson
2020-04-30 08:55:53 -05:00
committed by Nate Prewitt
parent bfb93d4b7d
commit db47b9b4a0
+14 -6
View File
@@ -90,14 +90,22 @@ except (AssertionError, ValueError):
"version!".format(urllib3.__version__, chardet.__version__),
RequestsDependencyWarning)
# Attempt to enable urllib3's SNI support, if possible
# Attempt to enable urllib3's fallback for SNI support
# if the standard library doesn't support SNI or the
# 'ssl' library isn't available.
try:
from urllib3.contrib import pyopenssl
pyopenssl.inject_into_urllib3()
try:
import ssl
except ImportError:
ssl = None
# Check cryptography version
from cryptography import __version__ as cryptography_version
_check_cryptography(cryptography_version)
if not getattr(ssl, "HAS_SNI", False):
from urllib3.contrib import pyopenssl
pyopenssl.inject_into_urllib3()
# Check cryptography version
from cryptography import __version__ as cryptography_version
_check_cryptography(cryptography_version)
except ImportError:
pass