Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pyOpenSSL only when ssl doesn't support SNI #4591

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import urllib3
import chardet
import ssl
import warnings
from .exceptions import RequestsDependencyWarning

Expand Down Expand Up @@ -90,16 +91,17 @@ def _check_cryptography(cryptography_version):
"version!".format(urllib3.__version__, chardet.__version__),
RequestsDependencyWarning)

# Attempt to enable urllib3's SNI support, if possible
try:
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
if not getattr(ssl, 'HAS_SNI'):
# Attempt to enable urllib3's SNI support, if possible
try:
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

# urllib3's DependencyWarnings should be silenced.
from urllib3.exceptions import DependencyWarning
Expand Down