aio-libs/aiohttp · warning · LookupError
No proxies found for
Error message
No proxies found for `{url!s}` in the env What it means
get_env_proxy_for_url raises LookupError when no proxy environment variable (HTTP_PROXY/http_proxy/HTTPS_PROXY/https_proxy) matches the URL's scheme. After confirming the host is not bypassed, the function looks up the scheme in the proxies-from-env dict and raises if the key is missing.
Solutions
- Set both HTTP_PROXY and HTTPS_PROXY environment variables
- Ensure env var names match the expected scheme (HTTPS_PROXY for https:// URLs)
- Pass the proxy explicitly: session.get(url, proxy='http://proxy:8080')
- Check for typos in env var names (e.g. HTTPS_PROXY vs HTTPS_PROXY)
Example fix
# before (only HTTP_PROXY set, request is HTTPS)
export HTTP_PROXY=http://proxy:3128
# session.get('https://api.example.com/data') raises
# after
export HTTP_PROXY=http://proxy:3128
export HTTPS_PROXY=http://proxy:3128 Defensive patterns
Strategy: validation
Validate before calling
import os
def get_proxy_for_scheme(scheme):
key = f'{scheme.upper()}_PROXY'
return os.environ.get(key) or os.environ.get(key.lower())
proxy = get_proxy_for_scheme(url.scheme)
if proxy is None:
logger.warning('No proxy env var for scheme %s', url.scheme) 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 'No proxies found' in str(e):
proxy, proxy_auth = None, None # direct connection
raise Prevention
- Set both HTTP_PROXY and HTTPS_PROXY in environments that use proxies
- Verify env var propagation in containers and subprocesses
- Use explicit proxy= parameter for deterministic proxy behavior
When it happens
Trigger: Calling get_env_proxy_for_url for an https:// URL when only HTTP_PROXY is set (not HTTPS_PROXY), or vice versa. Also triggered for non-standard schemes like ftp:// when no matching proxy env var exists.
Common situations: HTTP_PROXY is set but HTTPS_PROXY is missing, and the code makes an HTTPS request; env var case mismatch (some systems need lowercase http_proxy); proxy env vars not propagated into a container or subprocess.
Related errors
- No .netrc file found
- Proxying is disallowed 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/23009cf77ccd8efa.
Report an issue: GitHub.
Appendix: source
Thrown at aiohttp/helpers.py:299
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]"
@functools.lru_cache(maxsize=56)
def parse_mimetype(mimetype: str) -> MimeType:
"""Parses a MIME type into its components.
mimetype is a MIME type string.
View on GitHub (pinned to d041d4d0fd)