File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121 startup. OpenSSL reads SSL_CERT_FILE ahead of its compiled-in path, so
2222 stdlib SSL operations get a working CA bundle.
2323
24- Only sets the variable when it isn't already set, so an explicit user
25- override (e.g. `export SSL_CERT_FILE=/path/to/ca.pem`) still wins.
24+ Falls back to certifi only when SSL_CERT_FILE is unset OR points at a
25+ path that doesn't exist on disk. A valid user override (e.g. a corporate
26+ CA bundle at `export SSL_CERT_FILE=/opt/corp/ca.pem`) is preserved;
27+ a stale or typo'd path gets corrected to certifi.
2628
2729References:
2830 macadmins/python#38
2931 gregneagle/relocatable-python#13
3032"""
3133import os
34+ import os .path
3235
33- if "SSL_CERT_FILE" not in os .environ :
36+
37+ def _ssl_cert_file_is_valid ():
38+ path = os .environ .get ("SSL_CERT_FILE" )
39+ return bool (path ) and os .path .isfile (path )
40+
41+
42+ if not _ssl_cert_file_is_valid ():
3443 try :
3544 import certifi
3645 except ImportError :
You can’t perform that action at this time.
0 commit comments