diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-10-05 08:32:05 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-10-06 05:45:16 +0530 |
commit | 4e3d1898a802b3729a56fabecbcd5a641a6ab19c (patch) | |
tree | 3a0dc6e7a66e7a54992357e3d8a97a104e5a5402 | |
parent | f85e6be42ec5e65c07a3f99927ca9dfe81d683f0 (diff) | |
download | hypervideo-pre-4e3d1898a802b3729a56fabecbcd5a641a6ab19c.tar.lz hypervideo-pre-4e3d1898a802b3729a56fabecbcd5a641a6ab19c.tar.xz hypervideo-pre-4e3d1898a802b3729a56fabecbcd5a641a6ab19c.zip |
Workaround ssl errors in mingw python
Closes #1151
-rw-r--r-- | yt_dlp/utils.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index b79b79688..8b5b15103 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -2373,13 +2373,20 @@ def make_HTTPS_handler(params, **kwargs): context.check_hostname = opts_check_certificate context.verify_mode = ssl.CERT_REQUIRED if opts_check_certificate else ssl.CERT_NONE if opts_check_certificate: - # Work around the issue in load_default_certs when there are bad certificates. See: - # https://github.com/yt-dlp/yt-dlp/issues/1060, - # https://bugs.python.org/issue35665, https://bugs.python.org/issue4531 - if sys.platform == 'win32': - for storename in ('CA', 'ROOT'): - _ssl_load_windows_store_certs(context, storename) - context.set_default_verify_paths() + try: + context.load_default_certs() + # Work around the issue in load_default_certs when there are bad certificates. See: + # https://github.com/yt-dlp/yt-dlp/issues/1060, + # https://bugs.python.org/issue35665, https://bugs.python.org/issue45312 + except ssl.SSLError: + # enum_certificates is not present in mingw python. See https://github.com/yt-dlp/yt-dlp/issues/1151 + if sys.platform == 'win32' and hasattr(ssl, 'enum_certificates'): + # Create a new context to discard any certificates that were already loaded + context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + context.check_hostname, context.verify_mode = True, ssl.CERT_REQUIRED + for storename in ('CA', 'ROOT'): + _ssl_load_windows_store_certs(context, storename) + context.set_default_verify_paths() return YoutubeDLHTTPSHandler(params, context=context, **kwargs) |