aio-libs/aiohttp · warning · LookupError
Proxying is disallowed for
Error message
Proxying is disallowed for `{url.host!r}` What it means
get_env_proxy_for_url raises LookupError when the URL's host matches the proxy_bypass list (typically the NO_PROXY environment variable). This means proxying to that host is explicitly disallowed by the environment configuration, so aiohttp refuses to route the request through a proxy.
Solutions
- Remove the host from the NO_PROXY environment variable if proxying is actually intended
- Pass the proxy explicitly via the proxy= parameter to bypass env resolution: session.get(url, proxy='http://proxy:8080')
- Adjust NO_PROXY patterns to be more specific so they do not match the intended target
Example fix
# before (NO_PROXY=localhost causes this)
proxy, proxy_auth = get_env_proxy_for_url(URL('http://localhost:8080/api'))
# after — pass proxy explicitly, bypassing env check
resp = await session.get('http://localhost:8080/api', proxy='http://corporate-proxy:3128') Defensive patterns
Strategy: fallback
Validate before calling
import os
from urllib.request import proxy_bypass
def can_proxy(host):
return not (host and proxy_bypass(host))
if not can_proxy(url.host):
logger.info('Host %s is in NO_PROXY; using direct connection', url.host) Try / catch
from aiohttp.helpers import get_env_proxy_for_url
try:
proxy, proxy_auth = get_env_proxy_for_url(url)
except LookupError as e:
if 'disallowed' in str(e).lower():
proxy, proxy_auth = None, None # direct connection
raise Prevention
- Review NO_PROXY env var for overly broad patterns
- Use explicit proxy= parameter when you must proxy despite NO_PROXY
- Log the NO_PROXY configuration at startup for debugging
When it happens
Trigger: Calling get_env_proxy_for_url(url) when url.host is in the NO_PROXY/no_proxy list. The proxy_bypass function (from urllib.request) returns True for hosts matching NO_PROXY patterns like 'localhost', '127.0.0.1', '*.internal', etc.
Common situations: NO_PROXY includes 'localhost' but code tries to use an env proxy for a localhost URL; NO_PROXY wildcard patterns that unexpectedly match the target host; corporate environments with broad NO_PROXY ranges that catch internal service hosts.
Related errors
- No .netrc file found
- No proxies found for
- aiohttp only supports http(s) proxies
- No entry for found in the `.netrc` file.
- base_url must have a trailing '/'
AI-assisted analysis of aio-libs/aiohttp@d041d4d0fd (2026-08-11).
Data as JSON: /api/errors/9fe2ff57d14a7b84.
Report an issue: GitHub.
Appendix: 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 d041d4d0fd)