Skip to content
Myr

prefer certifi's bundle to the OS bundle

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

authored by Shivaram Lingamneni · committed by Shivaram Lingamneni · parent e1528ce · Browse files · 2 files+18 added−9 removed
This commit

State

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

Diff stats

2 files+18 added−9 removed

  • other:+18 added−9 removed

2 files+18 added−9 removed

modified:requests/models.py+4 added-5 removed
25 unmodified lines
26 ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects,27 URLRequired, SSLError, MissingSchema, InvalidSchema, InvalidURL)28from .utils import (29 get_encoding_from_headers, stream_untransfer, guess_filename, requote_uri,30 dict_from_string, stream_decode_response_unicode, get_netrc_auth, CA_BUNDLE_PATH)30 dict_from_string, stream_decode_response_unicode, get_netrc_auth,31 DEFAULT_CA_BUNDLE_PATH)32from .compat import (33 urlparse, urlunparse, urljoin, urlsplit, urlencode, str, bytes,34 SimpleCookie, is_py2)35
505 unmodified lines
541 # Curl compatibility.542 if not cert_loc and self.config.get('trust_env'):543 cert_loc = os.environ.get('CURL_CA_BUNDLE')544544 # Use the operating system's bundle, if it can be found.545 if not cert_loc:546 cert_loc = CA_BUNDLE_PATH546 cert_loc = DEFAULT_CA_BUNDLE_PATH547548 # Use the awesome certifi list.548 if not cert_loc:550 cert_loc = __import__('certifi').where()549 raise Exception("Could not find a suitable SSL CA certificate bundle.")550551 conn.cert_reqs = 'CERT_REQUIRED'552 conn.ca_certs = cert_loc553 else:
291 unmodified lines
modified:requests/utils.py+14 added-4 removed
19 unmodified lines
20from .compat import parse_http_list as _parse_list_header21from .compat import quote, cookielib, SimpleCookie, is_py2, urlparse22from .compat import basestring, bytes, str2324CERTIFI_BUNDLE_PATH = None25try:26 # see if requests's own CA certificate bundle is installed27 import certifi28 CERTIFI_BUNDLE_PATH = certifi.where()29except ImportError:30 pass3132NETRC_FILES = ('.netrc', '_netrc')3334# common paths for the OS's CA certificate bundle35POSSIBLE_CA_BUNDLE_PATHS = [29 # Red Hat, CentOS, Fedora and friends:36 # Red Hat, CentOS, Fedora and friends (provided by the ca-certificates package):37 '/etc/pki/tls/certs/ca-bundle.crt',31 # Ubuntu and friends:38 # Ubuntu, Debian, and friends (provided by the ca-certificates package):39 '/etc/ssl/certs/ca-certificates.crt',40 # FreeBSD (provided by the ca_root_nss package):41 '/usr/local/share/certs/ca-root-nss.crt',42]4337def get_ca_bundle_path():44def get_os_ca_bundle_path():45 """Try to pick an available CA certificate bundle provided by the OS."""46 for path in POSSIBLE_CA_BUNDLE_PATHS:47 if os.path.exists(path):48 return path49 return None5043CA_BUNDLE_PATH = get_ca_bundle_path()51# if certifi is installed, use its CA bundle;52# otherwise, try and use the OS bundle53DEFAULT_CA_BUNDLE_PATH = CERTIFI_BUNDLE_PATH or get_os_ca_bundle_path()5455def dict_to_sequence(d):56 """Returns an internal sequence dictionary update."""57
444 unmodified lines