From 2c6dcb65fb612fc5bc5c61937bf438d3c473d8d0 Mon Sep 17 00:00:00 2001 From: coletdev Date: Sat, 28 May 2022 15:46:36 +1200 Subject: [PATCH] [utils] Send HTTP/1.1 ALPN extension (#3889) Some servers may reject requests if not sent (e.g. fingerprinting) Fixes #3878 Authored by: coletdjnz --- yt_dlp/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index 9da8bb293..b0300b724 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -948,6 +948,13 @@ def make_HTTPS_handler(params, **kwargs): password=params.get('client_certificate_password')) except ssl.SSLError: raise YoutubeDLError('Unable to load client certificate') + + # Some servers may reject requests if ALPN extension is not sent. See: + # https://github.com/python/cpython/issues/85140 + # https://github.com/yt-dlp/yt-dlp/issues/3878 + with contextlib.suppress(NotImplementedError): + context.set_alpn_protocols(['http/1.1']) + return YoutubeDLHTTPSHandler(params, context=context, **kwargs)