Skip to content

Commit 22d8f8e

Browse files
authored
Merge pull request #344 from xloem/https_ctx
Detect empty HTTPS contexts.
2 parents aaefac1 + 548a2ec commit 22d8f8e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

github_backup/github_backup.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import re
1616
import select
1717
import socket
18+
import ssl
1819
import subprocess
1920
import sys
2021
import time
@@ -36,6 +37,18 @@
3637
FILE_URI_PREFIX = "file://"
3738
logger = logging.getLogger(__name__)
3839

40+
https_ctx = ssl.create_default_context()
41+
if not https_ctx.get_ca_certs():
42+
import warnings
43+
warnings.warn('\n\nYOUR DEFAULT CA CERTS ARE EMPTY.\n' +
44+
'PLEASE POPULATE ANY OF:' +
45+
''.join([
46+
'\n - ' + x
47+
for x in ssl.get_default_verify_paths()
48+
if type(x) is str
49+
]) + '\n', stacklevel=2)
50+
import certifi
51+
https_ctx = ssl.create_default_context(cafile=certifi.where())
3952

4053
def logging_subprocess(
4154
popenargs, stdout_log_level=logging.DEBUG, stderr_log_level=logging.ERROR, **kwargs
@@ -666,7 +679,7 @@ def _get_response(request, auth, template):
666679
while True:
667680
should_continue = False
668681
try:
669-
r = urlopen(request)
682+
r = urlopen(request, context=https_ctx)
670683
except HTTPError as exc:
671684
errors, should_continue = _request_http_error(exc, auth, errors) # noqa
672685
r = exc

0 commit comments

Comments
 (0)