From 7073d95c56e3579ad72d3ddb74bdfd5cde03e0f5 Mon Sep 17 00:00:00 2001 From: Shian Chen Date: Wed, 26 Feb 2025 13:47:09 +0800 Subject: [PATCH] Update _client.py to fix bug when proxy_map contains None When proxy_map contains None as value, the library will throw an exception, the proposed changes will fix the error: proxy_map: {'http://': Proxy('http://sys-proxy-rd-relay.xxxx.org:8119'), 'https://': Proxy('http://sys-proxy-rd-relay.xxxx.org:8119'), 'all://localhost': None} Exception: File /usr/local/lib/python3.11/dist-packages/httpx/_urlparse.py:411, in normalize_port(port, scheme) 409 port_as_int = int(port) 410 except ValueError: --> 411 raise InvalidURL(f"Invalid port: {port!r}") 413 # See https://url.spec.whatwg.org/#url-miscellaneous 414 default_port = {"ftp": 21, "http": 80, "https": 443, "ws": 80, "wss": 443}.get( 415 scheme 416 ) InvalidURL: Invalid port: ':' --- httpx/_client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/httpx/_client.py b/httpx/_client.py index 2249231f8c..eadaa08cc0 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -707,6 +707,7 @@ def __init__( limits=limits, ) for key, proxy in proxy_map.items() + if proxy is not None } if mounts is not None: self._mounts.update( @@ -1422,6 +1423,7 @@ def __init__( limits=limits, ) for key, proxy in proxy_map.items() + if proxy is not None } if mounts is not None: self._mounts.update(