{"record":{"id":"206411a6b31ddd6b","repo":"aio-libs/aiohttp","slug":"no-entry-for-host-s-found-in-the-netrc-file","errorCode":null,"errorMessage":"No entry for {host!s} found in the `.netrc` file.","messagePattern":"No entry for (.+?) found in the `\\.netrc` file\\.","errorType":"exception","errorClass":"LookupError","httpStatus":null,"severity":"warning","filePath":"aiohttp/helpers.py","lineNumber":247,"sourceCode":"\n@frozen_dataclass_decorator\nclass ProxyInfo:\n    proxy: URL\n    proxy_auth: str | None\n\n\ndef _auth_header_from_netrc(netrc_obj: netrc.netrc | None, host: str) -> str:\n    \"\"\"Return a ``Proxy-Authorization`` header value for ``host`` from netrc.\n\n    :raises LookupError: if ``netrc_obj`` is :py:data:`None` or if no\n            entry is found for the ``host``.\n    \"\"\"\n    if netrc_obj is None:\n        raise LookupError(\"No .netrc file found\")\n    auth_from_netrc = netrc_obj.authenticators(host)\n\n    if auth_from_netrc is None:\n        raise LookupError(f\"No entry for {host!s} found in the `.netrc` file.\")\n    login, account, password = auth_from_netrc\n\n    # TODO(PY311): username = login or account\n    # Up to python 3.10, account could be None if not specified,\n    # and login will be empty string if not specified. From 3.11,\n    # login and account will be empty string if not specified.\n    username = login if (login or account is None) else account\n\n    # TODO(PY311): Remove this, as password will be empty string\n    # if not specified\n    if password is None:\n        password = \"\"  # type: ignore[unreachable]\n\n    return encode_basic_auth(username, password)\n\n\ndef proxies_from_env() -> dict[str, ProxyInfo]:\n    proxy_urls = {","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/d041d4d0fd48c3f0832084d33be16cf1c4835f85/aiohttp/helpers.py#L229-L265","documentation":"_auth_header_from_netrc raises LookupError when a netrc object exists but has no authenticators entry for the specified proxy host. The netrc.netrc.authenticators(host) call returns None because no 'machine <host>' line matches.","triggerScenarios":"A .netrc file exists and is parsed, but it lacks a 'machine <proxy_host>' entry matching the proxy URL's host. The netrc file may have entries for other hosts but not for the specific proxy host aiohttp is resolving.","commonSituations":"netrc configured for a production proxy host but the code is pointed at a staging proxy with a different hostname; netrc has a 'default' entry but the host does not match; typo in the machine name in .netrc.","solutions":["Add a 'machine <proxy_host>' entry to ~/.netrc with login and password","Add a 'default' entry in .netrc as a catch-all fallback","Provide proxy credentials explicitly via the proxy_auth parameter","Verify the proxy hostname matches the netrc machine entry exactly"],"exampleFix":"# ~/.netrc before (no entry for proxy.corp.local)\nmachine api.example.com login user1 password pass1\n\n# ~/.netrc after\nmachine api.example.com login user1 password pass1\nmachine proxy.corp.local login proxyuser password proxypass","handlingStrategy":"fallback","validationCode":"import netrc\n\ndef check_netrc_entry(host):\n    try:\n        nrc = netrc.netrc()\n    except FileNotFoundError:\n        return False\n    return nrc.authenticators(host) is not None\n\nif not check_netrc_entry(proxy_host):\n    logger.warning('No netrc entry for %s; provide proxy_auth explicitly', proxy_host)","typeGuard":null,"tryCatchPattern":"try:\n    resp = await session.get(url, proxy=proxy_url)\nexcept LookupError as e:\n    if 'No entry' in str(e):\n        resp = await session.get(url, proxy=proxy_url, proxy_auth=BasicAuth('user', 'pass'))\n    raise","preventionTips":["Verify the exact proxy hostname matches the netrc 'machine' entry","Add a 'default' entry in .netrc as a safety net","Test netrc configuration with python -c 'import netrc; print(netrc.netrc().authenticators(\"host\"))'"],"tags":["proxy","netrc","authentication","configuration"],"backgroundTag":null,"analyzedSha":"d041d4d0fd48c3f0832084d33be16cf1c4835f85","analyzedAt":"2026-08-11T20:44:15.550Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}