aio-libs/aiohttp · warning · LookupError
Proxying is disallowed for `{url.host!r}`
Error message
Proxying is disallowed for `{url.host!r}` What it means
Raised by get_env_proxy_for_url when urllib.request.proxy_bypass(url.host) returns True, i.e. the host is on the no-proxy list (NO_PROXY env var or system bypass rules). LookupError signals that although env proxies exist, this destination must not be proxied.
Source
Thrown at aiohttp/helpers.py:293
if proxy.scheme in ("https", "wss"):
client_logger.warning(
"%s proxies %s are not supported, ignoring", proxy.scheme.upper(), proxy
)
continue
if netrc_obj and auth is None:
if proxy.host is not None:
try:
auth = _auth_header_from_netrc(netrc_obj, proxy.host)
except LookupError:
auth = None
ret[proto] = ProxyInfo(proxy, auth)
return ret
def get_env_proxy_for_url(url: URL) -> tuple[URL, str | None]:
"""Get a permitted proxy for the given URL from the env."""
if url.host is not None and proxy_bypass(url.host):
raise LookupError(f"Proxying is disallowed for `{url.host!r}`")
proxies_in_env = proxies_from_env()
try:
proxy_info = proxies_in_env[url.scheme]
except KeyError:
raise LookupError(f"No proxies found for `{url!s}` in the env")
else:
return proxy_info.proxy, proxy_info.proxy_auth
@frozen_dataclass_decorator
class MimeType:
type: str
subtype: str
suffix: str
parameters: "MultiDictProxy[str]"
View on GitHub (pinned to c0ef574e29)
Solutions
- Respect the bypass: do not call get_env_proxy_for_url for hosts in NO_PROXY.
- Check proxy_bypass(host) yourself before requesting a proxy.
- Adjust NO_PROXY env if the host genuinely should be proxied.
Example fix
// before
proxy, auth = get_env_proxy_for_url(url) # raises for internal hosts
// after
from urllib.request import proxy_bypass
if not proxy_bypass(url.host):
proxy, auth = get_env_proxy_for_url(url)
else:
proxy, auth = None, None Defensive patterns
Strategy: validation
Validate before calling
from urllib.request import proxy_bypass
def maybe_proxy(url):
if url.host and proxy_bypass(url.host):
return None, None
return get_env_proxy_for_url(url) Try / catch
try:
proxy, auth = get_env_proxy_for_url(url)
except LookupError:
proxy, auth = None, None Prevention
- Check proxy_bypass(host) before asking for an env proxy.
- Keep NO_PROXY accurate for internal/loopback hosts.
- Don't force-proxy hosts your policy intends to bypass.
When it happens
Trigger: Calling get_env_proxy_for_url(url) for a host listed in NO_PROXY='localhost,127.0.0.1,.internal'. Common when an app tries to forcibly route a localhost/internal request through an env-configured proxy.
Common situations: Corporate NO_PROXY includes the target domain; localhost/loopback explicitly bypassed; '*.corp' internal domains bypassed but code still requests a proxy.
Related errors
- No .netrc file found
- No proxies found for `{url!s}` in the env
- No entry for {host!s} found in the `.netrc` file.
- Invalid upgrade header
- Invalid connection header
AI-assisted analysis of aio-libs/aiohttp@c0ef574e29 (2026-08-04).
Data as JSON: /data/errors/9fe2ff57d14a7b84.json.
Report an issue: GitHub.