diff options
Diffstat (limited to 'yt_dlp')
-rw-r--r-- | yt_dlp/networking/common.py | 10 | ||||
-rw-r--r-- | yt_dlp/utils/networking.py | 8 |
2 files changed, 14 insertions, 4 deletions
diff --git a/yt_dlp/networking/common.py b/yt_dlp/networking/common.py index ab26a0628..3164df49b 100644 --- a/yt_dlp/networking/common.py +++ b/yt_dlp/networking/common.py @@ -262,9 +262,13 @@ class RequestHandler(abc.ABC): # Skip proxy scheme checks continue - # Scheme-less proxies are not supported - if urllib.request._parse_proxy(proxy_url)[0] is None: - raise UnsupportedRequest(f'Proxy "{proxy_url}" missing scheme') + try: + if urllib.request._parse_proxy(proxy_url)[0] is None: + # Scheme-less proxies are not supported + raise UnsupportedRequest(f'Proxy "{proxy_url}" missing scheme') + except ValueError as e: + # parse_proxy may raise on some invalid proxy urls such as "/a/b/c" + raise UnsupportedRequest(f'Invalid proxy url "{proxy_url}": {e}') scheme = urllib.parse.urlparse(proxy_url).scheme.lower() if scheme not in self._SUPPORTED_PROXY_SCHEMES: diff --git a/yt_dlp/utils/networking.py b/yt_dlp/utils/networking.py index ac355ddc8..e6515ec8e 100644 --- a/yt_dlp/utils/networking.py +++ b/yt_dlp/utils/networking.py @@ -98,7 +98,13 @@ def clean_proxies(proxies: dict, headers: HTTPHeaderDict): continue if proxy_url is not None: # Ensure proxies without a scheme are http. - proxy_scheme = urllib.request._parse_proxy(proxy_url)[0] + try: + proxy_scheme = urllib.request._parse_proxy(proxy_url)[0] + except ValueError: + # Ignore invalid proxy URLs. Sometimes these may be introduced through environment + # variables unrelated to proxy settings - e.g. Colab `COLAB_LANGUAGE_SERVER_PROXY`. + # If the proxy is going to be used, the Request Handler proxy validation will handle it. + continue if proxy_scheme is None: proxies[proxy_key] = 'http://' + remove_start(proxy_url, '//') |