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

  1. Set both HTTP_PROXY and HTTPS_PROXY environment variables
  2. Ensure env var names match the expected scheme (HTTPS_PROXY for https:// URLs)
  3. Pass the proxy explicitly: session.get(url, proxy='http://proxy:8080')
  4. 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

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


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)