Skip to content
Myr

Don't create default SSLContext if ssl module isn't present (#6724)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nate Prewitt · committed by GitHub · parent 145b539 · Browse files · 1 file+19 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+19 added−5 removed

  • other:+19 added−5 removed

1 file+19 added−5 removed

modified:src/requests/adapters.py+19 added-5 removed
71 unmodified lines
72DEFAULT_POOLSIZE = 1073DEFAULT_RETRIES = 074DEFAULT_POOL_TIMEOUT = None7576_preloaded_ssl_context = create_urllib3_context()77_preloaded_ssl_context.load_verify_locations(78 extract_zipped_paths(DEFAULT_CA_BUNDLE_PATH)79)7677try:78 import ssl # noqa: F4017980 _preloaded_ssl_context = create_urllib3_context()81 _preloaded_ssl_context.load_verify_locations(82 extract_zipped_paths(DEFAULT_CA_BUNDLE_PATH)83 )84except ImportError:85 # Bypass default SSLContext creation when Python86 # interpreter isn't built with the ssl module.87 _preloaded_ssl_context = None888990def _urllib3_request_context(91 request: "PreparedRequest",92 verify: "bool | str | None",93 client_cert: "typing.Tuple[str, str] | str | None",
3 unmodified lines
97 pool_kwargs = {}98 parsed_request_url = urlparse(request.url)99 scheme = parsed_request_url.scheme.lower()100 port = parsed_request_url.port101102 # Determine if we have and should use our default SSLContext103 # to optimize performance on standard requests.104 poolmanager_kwargs = getattr(poolmanager, "connection_pool_kw", {})105 has_poolmanager_ssl_context = poolmanager_kwargs.get("ssl_context")106 should_use_default_ssl_context = (107 _preloaded_ssl_context is not None and not has_poolmanager_ssl_context108 )109110 cert_reqs = "CERT_REQUIRED"111 if verify is False:112 cert_reqs = "CERT_NONE"99 elif verify is True and not has_poolmanager_ssl_context:113 elif verify is True and should_use_default_ssl_context:114 pool_kwargs["ssl_context"] = _preloaded_ssl_context115 elif isinstance(verify, str):116 if not os.path.isdir(verify):117 pool_kwargs["ca_certs"] = verify
602 unmodified lines