aio-libs/aiohttp · warning · LookupError
No .netrc file found
Error message
No .netrc file found
What it means
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.
Source
Thrown at aiohttp/helpers.py:243
client_logger.warning("Could not read .netrc file: %s", e)
return None
@frozen_dataclass_decorator
class ProxyInfo:
proxy: URL
proxy_auth: str | None
def _auth_header_from_netrc(netrc_obj: netrc.netrc | None, host: str) -> str:
"""Return a ``Proxy-Authorization`` header value for ``host`` from netrc.
:raises LookupError: if ``netrc_obj`` is :py:data:`None` or if no
entry is found for the ``host``.
"""
if netrc_obj is None:
raise LookupError("No .netrc file found")
auth_from_netrc = netrc_obj.authenticators(host)
if auth_from_netrc is None:
raise LookupError(f"No entry for {host!s} found in the `.netrc` file.")
login, account, password = auth_from_netrc
# TODO(PY311): username = login or account
# Up to python 3.10, account could be None if not specified,
# and login will be empty string if not specified. From 3.11,
# login and account will be empty string if not specified.
username = login if (login or account is None) else account
# TODO(PY311): Remove this, as password will be empty string
# if not specified
if password is None:
password = "" # type: ignore[unreachable]
return encode_basic_auth(username, password)View on GitHub (pinned to c0ef574e29)
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.
Example fix
// before # no .netrc, trust_env=True, proxy requires auth // after # chmod 600 ~/.netrc with: machine proxy.local login me password xxx
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
import os
netrc_path = Path(os.environ.get('NETRC') or (Path.home() / '.netrc'))
if not netrc_path.is_file():
raise FileNotFoundError(f'configure {netrc_path}') Try / catch
try:
auth = _auth_header_from_netrc(netrc_obj, host)
except LookupError:
auth = None # fall back to no netrc auth Prevention
- 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.
When it happens
Trigger: 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.
Common situations: CI/container environments without HOME or .netrc; misconfigured NETRC env var pointing to a non-existent path; permissions blocking the file.
Related errors
- No entry for {host!s} found in the `.netrc` file.
- Proxying is disallowed for `{url.host!r}`
- No proxies found for `{url!s}` in the env
- Invalid upgrade header
- Invalid connection header
AI-assisted analysis of aio-libs/aiohttp@c0ef574e29 (2026-08-04).
Data as JSON: /data/errors/9993a027e5f2c840.json.
Report an issue: GitHub.