{"record":{"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/d041d4d0fd48c3f0832084d33be16cf1c4835f85/aiohttp/helpers.py#L275-L311","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before (NO_PROXY=localhost causes this)\nproxy, proxy_auth = get_env_proxy_for_url(URL('http://localhost:8080/api'))\n\n# after — pass proxy explicitly, bypassing env check\nresp = await session.get('http://localhost:8080/api', proxy='http://corporate-proxy:3128')","handlingStrategy":"fallback","validationCode":"import os\nfrom urllib.request import proxy_bypass\n\ndef can_proxy(host):\n    return not (host and proxy_bypass(host))\n\nif not can_proxy(url.host):\n    logger.info('Host %s is in NO_PROXY; using direct connection', url.host)","typeGuard":null,"tryCatchPattern":"from aiohttp.helpers import get_env_proxy_for_url\ntry:\n    proxy, proxy_auth = get_env_proxy_for_url(url)\nexcept LookupError as e:\n    if 'disallowed' in str(e).lower():\n        proxy, proxy_auth = None, None  # direct connection\n    raise","preventionTips":["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"],"tags":["proxy","no-proxy","environment","configuration"],"backgroundTag":null,"analyzedSha":"d041d4d0fd48c3f0832084d33be16cf1c4835f85","analyzedAt":"2026-08-11T20:44:15.550Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}