aio-libs/aiohttp · warning · LookupError

No entry for found in the `.netrc` file.

Error message

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

What it means

_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.

Solutions

  1. Add a 'machine <proxy_host>' entry to ~/.netrc with login and password
  2. Add a 'default' entry in .netrc as a catch-all fallback
  3. Provide proxy credentials explicitly via the proxy_auth parameter
  4. Verify the proxy hostname matches the netrc machine entry exactly

Example fix

# ~/.netrc before (no entry for proxy.corp.local)
machine api.example.com login user1 password pass1

# ~/.netrc after
machine api.example.com login user1 password pass1
machine proxy.corp.local login proxyuser password proxypass
Defensive patterns

Strategy: fallback

Validate before calling

import netrc

def check_netrc_entry(host):
    try:
        nrc = netrc.netrc()
    except FileNotFoundError:
        return False
    return nrc.authenticators(host) is not None

if not check_netrc_entry(proxy_host):
    logger.warning('No netrc entry for %s; provide proxy_auth explicitly', proxy_host)

Try / catch

try:
    resp = await session.get(url, proxy=proxy_url)
except LookupError as e:
    if 'No entry' in str(e):
        resp = await session.get(url, proxy=proxy_url, proxy_auth=BasicAuth('user', 'pass'))
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of aio-libs/aiohttp@d041d4d0fd (2026-08-11). Data as JSON: /api/errors/206411a6b31ddd6b. Report an issue: GitHub.

Appendix: 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 d041d4d0fd)