diff --git a/requests/utils.py b/requests/utils.py index fd186b88..6892713a 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -706,6 +706,10 @@ def should_bypass_proxies(url, no_proxy): no_proxy = get_proxy('no_proxy') parsed = urlparse(url) + if parsed.hostname is None: + # URLs don't always have hostnames, e.g. file:/// urls. + return True + if no_proxy: # We need to check whether we match here. We need to see if we match # the end of the hostname, both with and without the port. diff --git a/tests/test_utils.py b/tests/test_utils.py index 70ffa5fb..f34c630f 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -622,6 +622,7 @@ def test_urldefragauth(url, expected): ('http://172.16.1.12/', False), ('http://172.16.1.12:5000/', False), ('http://google.com:5000/v1.0/', False), + ('file:///some/path/on/disk', True), )) def test_should_bypass_proxies(url, expected, monkeypatch): """Tests for function should_bypass_proxies to check if proxy