diff options
author | Simon Sawicki <contact@grub4k.xyz> | 2024-05-22 16:22:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-22 16:22:25 +0200 |
commit | 3f7999533ebe41c2a579d91b4e4cb211cfcd3bc0 (patch) | |
tree | cacbb126302a969b3ec891f680491e657330f5f9 /yt_dlp/networking/_requests.py | |
parent | 4ccd73fea0f6f4be343e1ec7f22dd03799addcf8 (diff) |
[rh:requests] Patch support for `requests` 2.32.2+ (#9992)
Authored by: Grub4K
Diffstat (limited to 'yt_dlp/networking/_requests.py')
-rw-r--r-- | yt_dlp/networking/_requests.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/yt_dlp/networking/_requests.py b/yt_dlp/networking/_requests.py index 75eee8824..6397a2c0c 100644 --- a/yt_dlp/networking/_requests.py +++ b/yt_dlp/networking/_requests.py @@ -21,13 +21,14 @@ urllib3_version = tuple(int_or_none(x, default=0) for x in urllib3.__version__.s if urllib3_version < (1, 26, 17): raise ImportError('Only urllib3 >= 1.26.17 is supported') -if requests.__build__ < 0x023200: - raise ImportError('Only requests >= 2.32.0 is supported') +if requests.__build__ < 0x023100: + raise ImportError('Only requests >= 2.31.0 is supported') import requests.adapters import requests.utils import urllib3.connection import urllib3.exceptions +import urllib3.util from ._helper import ( InstanceStoreMixin, @@ -180,14 +181,25 @@ class RequestsHTTPAdapter(requests.adapters.HTTPAdapter): extra_kwargs['proxy_ssl_context'] = self._proxy_ssl_context return super().proxy_manager_for(proxy, **proxy_kwargs, **self._pm_args, **extra_kwargs) + # Skip `requests` internal verification; we use our own SSLContext + # requests 2.31.0+ def cert_verify(*args, **kwargs): - # Lean on our SSLContext for cert verification pass + # requests 2.31.0-2.32.1 def _get_connection(self, request, *_, proxies=None, **__): - # Lean on our SSLContext for cert verification return self.get_connection(request.url, proxies) + # requests 2.32.2+: Reimplementation without `_urllib3_request_context` + def get_connection_with_tls_context(self, request, verify, proxies=None, cert=None): + url = urllib3.util.parse_url(request.url).url + + manager = self.poolmanager + if proxy := select_proxy(url, proxies): + manager = self.proxy_manager_for(proxy) + + return manager.connection_from_url(url) + class RequestsSession(requests.sessions.Session): """ |