{"record":{"id":"9993a027e5f2c840","repo":"aio-libs/aiohttp","slug":"no-netrc-file-found","errorCode":null,"errorMessage":"No .netrc file found","messagePattern":"No \\.netrc file found","errorType":"exception","errorClass":"LookupError","httpStatus":null,"severity":"warning","filePath":"aiohttp/helpers.py","lineNumber":243,"sourceCode":"            client_logger.warning(\"Could not read .netrc file: %s\", e)\n\n    return None\n\n\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)","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/d041d4d0fd48c3f0832084d33be16cf1c4835f85/aiohttp/helpers.py#L225-L261","documentation":"_auth_header_from_netrc raises LookupError when the netrc_obj passed to it is None, meaning no .netrc file was found on the system. This function is called internally when aiohttp resolves proxy credentials from the netrc file for environment-configured proxies.","triggerScenarios":"Setting trust_env=True on a ClientSession and configuring a proxy via environment variables (HTTP_PROXY/HTTPS_PROXY) while expecting netrc-based proxy authentication, but no ~/.netrc file exists on the system. Also triggered when HOME is unset so netrc.netrc cannot locate the file.","commonSituations":"CI/CD pipelines without a .netrc file but with proxy env vars set; containers missing HOME or the .netrc file; corporate proxy setups that rely on netrc credentials deployed per-user but the deployment was skipped.","solutions":["Create a ~/.netrc file with the appropriate machine entry and credentials","Set the HOME environment variable to the correct home directory","Provide proxy credentials explicitly via the proxy_auth parameter instead of relying on netrc","Set trust_env=False if you do not want netrc-based proxy resolution"],"exampleFix":"# before\nsession = ClientSession(trust_env=True)\n# relies on netrc but file does not exist\n\n# after\n# Option 1: provide credentials explicitly\nfrom aiohttp import BasicAuth\nauth = BasicAuth('proxyuser', 'proxypass')\nsession = ClientSession(trust_env=True)\nawait session.get(url, proxy='http://proxy:8080', proxy_auth=auth)","handlingStrategy":"fallback","validationCode":"import os, netrc\n\ndef get_netrc_or_none():\n    try:\n        return netrc.netrc()\n    except (FileNotFoundError, netrc.NetrcParseError):\n        return None\n\nnetrc_obj = get_netrc_or_none()\nif netrc_obj is None:\n    logger.warning('No .netrc found; provide proxy_auth explicitly')","typeGuard":null,"tryCatchPattern":"try:\n    resp = await session.get(url, proxy=proxy_url)\nexcept LookupError as e:\n    if 'netrc' in str(e).lower():\n        # Fall back to explicit proxy auth\n        resp = await session.get(url, proxy=proxy_url, proxy_auth=BasicAuth('user', 'pass'))\n    raise","preventionTips":["Create a .netrc file in deployment environments that use proxies","Set trust_env=False when you do not need environment-based proxy/auth resolution","Provide proxy_auth explicitly instead of relying on netrc discovery"],"tags":["proxy","netrc","authentication","configuration","environment"],"backgroundTag":null,"analyzedSha":"d041d4d0fd48c3f0832084d33be16cf1c4835f85","analyzedAt":"2026-08-11T20:44:15.550Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}