From 4e7beef860aae511a79df97203c1be50dda35049 Mon Sep 17 00:00:00 2001 From: "John R. Lenton" Date: Tue, 26 Apr 2016 11:21:54 +0100 Subject: [PATCH] utils: let select_proxy not raise an exception when url has no hostname --- requests/utils.py | 5 ++++- tests/test_utils.py | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/requests/utils.py b/requests/utils.py index d0f39c0f..c08448cc 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -579,7 +579,10 @@ def select_proxy(url, proxies): """ proxies = proxies or {} urlparts = urlparse(url) - proxy = proxies.get(urlparts.scheme+'://'+urlparts.hostname) + if urlparts.hostname is None: + proxy = None + else: + proxy = proxies.get(urlparts.scheme+'://'+urlparts.hostname) if proxy is None: proxy = proxies.get(urlparts.scheme) return proxy diff --git a/tests/test_utils.py b/tests/test_utils.py index 5131e116..13d44df9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -325,6 +325,7 @@ def test_dotted_netmask(mask, expected): ('hTTp://u:p@Some.Host/path', 'http://some.host.proxy'), ('hTTp://u:p@Other.Host/path', 'http://http.proxy'), ('hTTps://Other.Host', None), + ('file:///etc/motd', None), )) def test_select_proxies(url, expected): """Make sure we can select per-host proxies correctly."""