{"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/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/helpers.py#L225-L261","documentation":"Raised by _auth_header_from_netrc when netrc_obj is None, i.e. no usable .netrc file was loaded (missing, unreadable, or unparseable). It is a LookupError, surfaced when the client tries to derive Proxy-Authorization from netrc for a proxy host.","triggerScenarios":"Trust env enabled with a proxy URL whose host has no credentials, while no .netrc exists at $NETRC or in the home directory. The lookup is invoked from proxies_from_env when proxy auth is needed and not in the URL.","commonSituations":"CI/container environments without HOME or .netrc; misconfigured NETRC env var pointing to a non-existent path; permissions blocking the file.","solutions":["Create a valid ~/.netrc (chmod 600) with a 'machine <proxyhost>' entry.","Set NETRC env var to an absolute readable file path.","Pass proxy auth explicitly via the proxy URL or trust_env=False with explicit connector config."],"exampleFix":"// before\n# no .netrc, trust_env=True, proxy requires auth\n// after\n# chmod 600 ~/.netrc with: machine proxy.local login me password xxx","handlingStrategy":"validation","validationCode":"from pathlib import Path\nimport os\nnetrc_path = Path(os.environ.get('NETRC') or (Path.home() / '.netrc'))\nif not netrc_path.is_file():\n    raise FileNotFoundError(f'configure {netrc_path}')","typeGuard":null,"tryCatchPattern":"try:\n    auth = _auth_header_from_netrc(netrc_obj, host)\nexcept LookupError:\n    auth = None  # fall back to no netrc auth","preventionTips":["Ship a readable ~/.netrc (chmod 600) in containerized deployments.","Set NETRC to an absolute path you control.","Pass explicit proxy auth instead of relying on netrc when the file is optional."],"tags":["netrc","proxy","auth","config","env"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}