python-poetry/poetry · error · PackageNotFoundError

Package [{name}] not found.

Error message

Package [{name}] not found.

What it means

Raised by HTTPRepository._get_page when the package's simple index page returns no response (http_repository.py:576-581). _get_response returns None on HTTP 404, 401, or 403 (http_repository.py:544-551), so this single message covers both genuine not-found and authentication/authorization failures — the code cannot distinguish them at this layer.

Source

Thrown at src/poetry/repositories/http_repository.py:581

    def _get_prefer_json_header(self) -> dict[str, str]:
        # Prefer json, but accept anything for backwards compatibility.
        # Although the more specific value should be preferred to the less specific one
        # according to https://developer.mozilla.org/en-US/docs/Glossary/Quality_values,
        # we add a quality value because some servers still prefer html without one.
        return {"Accept": "application/vnd.pypi.simple.v1+json, */*;q=0.1"}

    def _is_json_response(self, response: requests.Response) -> bool:
        return (
            response.headers.get("Content-Type", "").split(";")[0].strip()
            == "application/vnd.pypi.simple.v1+json"
        )

    def _get_page(self, name: NormalizedName) -> LinkSource:
        response = self._get_response(
            f"/{name}/", headers=self._get_prefer_json_header()
        )
        if not response:
            raise PackageNotFoundError(f"Package [{name}] not found.")
        if self._is_json_response(response):
            return SimpleJsonPage(response.url, response.json())
        return HTMLPage(response.url, response.text)

    def log_age_filtered_versions(self, *, level: str, reset: bool) -> None:
        if not self._age_filtered_versions:
            return
        self._log(
            "The following package versions were ignored"
            f" due to solver.min-release-age={self._min_release_age}",
            level=level,
        )
        for name in sorted(self._age_filtered_versions):
            versions = ", ".join(
                str(v) for v in sorted(self._age_filtered_versions[name])
            )
            self._log(f"{name}: {versions}", level=level)
        if reset:

View on GitHub (pinned to 92b74dcfe3)

Solutions

  1. If the repository needs auth, configure credentials: `poetry config http-basic.<source> <user> <pass>` (or set POETRY_HTTP_BASIC_*).
  2. Verify the package name spelling and that it actually exists on that index.
  3. Confirm the [[tool.poetry.source]] URL is the correct simple-index base.
  4. If the package is on PyPI, ensure a PyPI source is in the pool (it is by default) and not disabled.

Example fix

// before
[[tool.poetry.source]]
name = "private"
url = "https://repo.example.com/simple/"
// (no credentials configured -> 401 -> 'Package not found')
// after
poetry config http-basic.private myuser mytoken
Defensive patterns

Strategy: validation

Validate before calling

# Confirm the package exists AND auth works before resolving
resp = repository.session.get(f"{repository._url}/{name}/", timeout=10)
if resp.status_code in (401, 403):
    raise PermissionError(f"auth missing for {repository.name}; configure http-basic.{repository.name}")
if resp.status_code == 404:
    raise LookupError(f"{name} not found on {repository.name}")

Try / catch

from poetry.repositories.exceptions import PackageNotFoundError
try:
    page = repository._get_page(name)
except PackageNotFoundError:
    log.warning("%s not found on %s (check name and auth)", name, repository.name)
    raise

Prevention

When it happens

Trigger: repository.package() / package lookup for a name not present on the configured HTTP repository; or when the repository requires credentials that were not supplied/configured (401/403 collapsed to None).

Common situations: Private repository credentials missing (no http-basic config); package name typo; package exists on PyPI but the project only configured a private source; the source URL points at the wrong path.

Related errors


AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04). Data as JSON: /data/errors/d0681550952f2d65.json. Report an issue: GitHub.