Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve message for ProxySchemeUnknown exception #2107

Merged
merged 1 commit into from Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/urllib3/exceptions.py
Expand Up @@ -289,7 +289,17 @@ class ProxySchemeUnknown(AssertionError, URLSchemeUnknown):
# TODO(t-8ch): Stop inheriting from AssertionError in v2.0.

def __init__(self, scheme):
message = "Not supported proxy scheme %s" % scheme
# 'localhost' is here because our URL parser parses
# localhost:8080 -> scheme=localhost, remove if we fix this.
if scheme == "localhost":
scheme = None
if scheme is None:
message = "Proxy URL had no scheme, should start with http:// or https://"
else:
message = (
"Proxy URL had unsupported scheme %s, should use http:// or https://"
% scheme
)
super(ProxySchemeUnknown, self).__init__(message)


Expand Down
22 changes: 22 additions & 0 deletions test/with_dummyserver/test_proxy_poolmanager.py
Expand Up @@ -23,6 +23,7 @@
ConnectTimeoutError,
MaxRetryError,
ProxyError,
ProxySchemeUnknown,
ProxySchemeUnsupported,
SSLError,
)
Expand Down Expand Up @@ -502,6 +503,27 @@ def test_scheme_host_case_insensitive(self):
r = http.request("GET", "%s/" % self.https_url.upper())
assert r.status == 200

@pytest.mark.parametrize(
"url, error_msg",
[
(
"127.0.0.1",
"Proxy URL had no scheme, should start with http:// or https://",
),
(
"localhost:8080",
"Proxy URL had no scheme, should start with http:// or https://",
),
(
"ftp://google.com",
"Proxy URL had unsupported scheme ftp, should use http:// or https://",
),
],
)
def test_invalid_schema(self, url, error_msg):
with pytest.raises(ProxySchemeUnknown, match=error_msg):
proxy_from_url(url)


@pytest.mark.skipif(not HAS_IPV6, reason="Only runs on IPv6 systems")
class TestIPv6HTTPProxyManager(IPv6HTTPDummyProxyTestCase):
Expand Down