{"id":"9fe2ff57d14a7b84","repo":"aio-libs/aiohttp","slug":"proxying-is-disallowed-for-url-host-r","errorCode":null,"errorMessage":"Proxying is disallowed for `{url.host!r}`","messagePattern":"Proxying is disallowed for `(.+?)`","errorType":"exception","errorClass":"LookupError","httpStatus":null,"severity":"warning","filePath":"aiohttp/helpers.py","lineNumber":293,"sourceCode":"        if proxy.scheme in (\"https\", \"wss\"):\n            client_logger.warning(\n                \"%s proxies %s are not supported, ignoring\", proxy.scheme.upper(), proxy\n            )\n            continue\n        if netrc_obj and auth is None:\n            if proxy.host is not None:\n                try:\n                    auth = _auth_header_from_netrc(netrc_obj, proxy.host)\n                except LookupError:\n                    auth = None\n        ret[proto] = ProxyInfo(proxy, auth)\n    return ret\n\n\ndef get_env_proxy_for_url(url: URL) -> tuple[URL, str | None]:\n    \"\"\"Get a permitted proxy for the given URL from the env.\"\"\"\n    if url.host is not None and proxy_bypass(url.host):\n        raise LookupError(f\"Proxying is disallowed for `{url.host!r}`\")\n\n    proxies_in_env = proxies_from_env()\n    try:\n        proxy_info = proxies_in_env[url.scheme]\n    except KeyError:\n        raise LookupError(f\"No proxies found for `{url!s}` in the env\")\n    else:\n        return proxy_info.proxy, proxy_info.proxy_auth\n\n\n@frozen_dataclass_decorator\nclass MimeType:\n    type: str\n    subtype: str\n    suffix: str\n    parameters: \"MultiDictProxy[str]\"\n\n","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/helpers.py#L275-L311","documentation":"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.","triggerScenarios":"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.","commonSituations":"Corporate NO_PROXY includes the target domain; localhost/loopback explicitly bypassed; '*.corp' internal domains bypassed but code still requests a proxy.","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."],"exampleFix":"// before\nproxy, auth = get_env_proxy_for_url(url)  # raises for internal hosts\n// after\nfrom urllib.request import proxy_bypass\nif not proxy_bypass(url.host):\n    proxy, auth = get_env_proxy_for_url(url)\nelse:\n    proxy, auth = None, None","handlingStrategy":"validation","validationCode":"from urllib.request import proxy_bypass\ndef maybe_proxy(url):\n    if url.host and proxy_bypass(url.host):\n        return None, None\n    return get_env_proxy_for_url(url)","typeGuard":null,"tryCatchPattern":"try:\n    proxy, auth = get_env_proxy_for_url(url)\nexcept LookupError:\n    proxy, auth = None, None","preventionTips":["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."],"tags":["proxy","no-proxy","env","config"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}