File tree Expand file tree Collapse file tree 2 files changed +26
-16
lines changed
Expand file tree Collapse file tree 2 files changed +26
-16
lines changed Original file line number Diff line number Diff line change 3737FILE_URI_PREFIX = "file://"
3838logger = logging .getLogger (__name__ )
3939
40+ # Setup SSL context with fallback chain
4041https_ctx = ssl .create_default_context ()
41- if not https_ctx .get_ca_certs ():
42- import warnings
43-
44- warnings .warn (
45- "\n \n YOUR DEFAULT CA CERTS ARE EMPTY.\n "
46- + "PLEASE POPULATE ANY OF:"
47- + "" .join (
48- ["\n - " + x for x in ssl .get_default_verify_paths () if type (x ) is str ]
49- )
50- + "\n " ,
51- stacklevel = 2 ,
52- )
53- import certifi
54-
55- https_ctx = ssl .create_default_context (cafile = certifi .where ())
42+ if https_ctx .get_ca_certs ():
43+ # Layer 1: Certificates pre-loaded from system (file-based)
44+ pass
45+ else :
46+ paths = ssl .get_default_verify_paths ()
47+ if (paths .cafile and os .path .exists (paths .cafile )) or (
48+ paths .capath and os .path .exists (paths .capath )
49+ ):
50+ # Layer 2: Cert paths exist, will be lazy-loaded on first use (directory-based)
51+ pass
52+ else :
53+ # Layer 3: Try certifi package as optional fallback
54+ try :
55+ import certifi
56+
57+ https_ctx = ssl .create_default_context (cafile = certifi .where ())
58+ except ImportError :
59+ # All layers failed - no certificates available anywhere
60+ sys .exit (
61+ "\n ERROR: No CA certificates found. Cannot connect to GitHub over SSL.\n \n "
62+ "Solutions you can explore:\n "
63+ " 1. pip install certifi\n "
64+ " 2. Alpine: apk add ca-certificates\n "
65+ " 3. Debian/Ubuntu: apt-get install ca-certificates\n \n "
66+ )
5667
5768
5869def logging_subprocess (
Original file line number Diff line number Diff line change 1-
You can’t perform that action at this time.
0 commit comments