aio-libs/aiohttp · warning · LookupError

No proxies found for `{url!s}` in the env

Error message

No proxies found for `{url!s}` in the env

What it means

Raised by get_env_proxy_for_url when proxies_from_env() returns a dict that has no entry for url.scheme (no matching http/https/ws/wss env proxy). LookupError; the URL is not in a bypass list but no proxy is configured for its scheme either.

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 c0ef574e29)

Solutions

  1. Set the scheme-specific env var: HTTPS_PROXY for https URLs, HTTP_PROXY for http.
  2. Verify with 'echo $HTTPS_PROXY' (case matters on Linux).
  3. Don't call get_env_proxy_for_url unless you know a proxy applies for that scheme.

Example fix

// before
# only HTTP_PROXY set, calling for https:// url
// after
export HTTPS_PROXY=http://proxy.local:8080
Defensive patterns

Strategy: validation

Validate before calling

import os
needed = {'https': 'HTTPS_PROXY', 'http': 'HTTP_PROXY', 'ws': 'WS_PROXY', 'wss': 'WSS_PROXY'}
var = needed.get(url.scheme)
if var and not os.environ.get(var):
    raise EnvironmentError(f'set {var} for {url.scheme} requests')

Try / catch

try:
    proxy, auth = get_env_proxy_for_url(url)
except LookupError:
    proxy, auth = None, None  # direct connection

Prevention

When it happens

Trigger: Only HTTP_PROXY is set but the URL scheme is https (or vice versa); only ALL_PROXY set (aiohttp reads scheme-specific vars); ws/wss schemes with no WS_PROXY. getproxies() yields nothing for that scheme.

Common situations: Mixing HTTPS_PROXY/HTTP_PROXY casing on case-sensitive OSes; setting ALL_PROXY expecting aiohttp to honor it; targeting ws:// without WS_PROXY.

Related errors


AI-assisted analysis of aio-libs/aiohttp@c0ef574e29 (2026-08-04). Data as JSON: /data/errors/23009cf77ccd8efa.json. Report an issue: GitHub.