aio-libs/aiohttp · warning · LookupError

No entry for {host!s} found in the `.netrc` file.

Error message

No entry for {host!s} found in the `.netrc` file.

What it means

Raised by _auth_header_from_netrc when the .netrc loaded successfully but netrc.authenticators(host) returns None, meaning no 'machine', 'default', or matching entry exists for that host. LookupError, indicating the host simply isn't covered by the file.

Source

Thrown at aiohttp/helpers.py:247

@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)


def proxies_from_env() -> dict[str, ProxyInfo]:
    proxy_urls = {

View on GitHub (pinned to c0ef574e29)

Solutions

  1. Add a 'machine <exact-proxy-host> login <u> password <p>' line to .netrc.
  2. Add a 'default' fallback line if appropriate.
  3. Ensure the hostname string matches what getproxies() reports (host part of the proxy URL).

Example fix

// before
# .netrc has: machine otherproxy login x password y
// after
# .netrc add: machine correctproxy.example.com login x password y
Defensive patterns

Strategy: validation

Validate before calling

import netrc
nrc = netrc.netrc()
if nrc.authenticators(host) is None:
    raise LookupError(f'add a machine {host} entry to .netrc')

Try / catch

try:
    auth = _auth_header_from_netrc(netrc_obj, host)
except LookupError:
    auth = None

Prevention

When it happens

Trigger: A proxy host has no matching 'machine <host>' line and no 'default' line in .netrc. The client attempted netrc-based proxy auth and could not find credentials for the specific proxy host.

Common situations: Typo in the machine hostname in .netrc; using an IP in code but a FQDN in netrc; relying on 'default' that was forgotten; proxy host changed after refactor.

Related errors


AI-assisted analysis of aio-libs/aiohttp@c0ef574e29 (2026-08-04). Data as JSON: /data/errors/206411a6b31ddd6b.json. Report an issue: GitHub.