Skip to content

Commit 3ab1b19

Browse files
committed
also look for path
1 parent 489aae7 commit 3ab1b19

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

managed_python_sitecustomize.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,25 @@
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
2729
References:
2830
macadmins/python#38
2931
gregneagle/relocatable-python#13
3032
"""
3133
import 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:

0 commit comments

Comments
 (0)