diff --git a/aiohttp/client.py b/aiohttp/client.py index bc6c0aaaa5d..79d33d6128a 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -611,6 +611,11 @@ async def _request( with suppress(LookupError): proxy, proxy_auth = get_env_proxy_for_url(url) + if proxy and not "http" in proxy.scheme: + raise ValueError( + "aiohttp works with http(s) proxy only currently." + ) + req = self._request_class( method, url, diff --git a/tests/test_client_request.py b/tests/test_client_request.py index 1b5d3a88fff..b7b4ec06b35 100644 --- a/tests/test_client_request.py +++ b/tests/test_client_request.py @@ -1570,3 +1570,10 @@ def test_request_info_tuple_new() -> None: ).real_url is url ) + + +def test_hostname_err(make_request: _RequestMaker) -> None: + with pytest.raises(ValueError): + make_request("get", "http://python.org/", proxy="socks5://127.0.0.1:80") + with pytest.raises(ValueError): + make_request("get", "http://python.org/", proxy="socks5h://127.0.0.1:80")