Skip to content

HTTP basic auth for pulling from private repositories does not work #4389

@trallnag

Description

@trallnag
  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Ubuntu 20.04
  • Poetry version: 1.1.7

Poetry config:

❯ poetry config --list
cache-dir = "/home/jfn/.cache/pypoetry"
experimental.new-installer = true
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.path = "{cache-dir}/virtualenvs"  # /home/jfn/.cache/pypoetry/virtualenvs

Content of pyproject.toml:

[tool.poetry]
name = "test"
version = "0.1.0"
description = ""
authors = []

[tool.poetry.dependencies]
python = "^3.8.11"

# my-repo
mypackage = "^1.5.4"

[[tool.poetry.source]]
name = "my-repo"
url = "https://[REDACTED]/artifactory/api/pypi/my-repo/simple/"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

Issue

I want to add a package to my dependencies. The package is hosted on a private PyPI repository. Authentication is done via Basic Auth. Doing the install with Pip works:

❯ pip install --extra-index-url https://$USERNAME:$PASSWORD@[REDACTED]/artifactory/api/pypi/my-repo/simple mypackage

But Poetry fails to perform the authentication. It doesn't matter if I use POETRY_HTTP_BASIC_PYPI_USERNAME and POETRY_HTTP_BASIC_PYPI_PASSWORD or use poetry config http-basic.my-repo username password. It always fails:

❯ poetry update
Updating dependencies
Resolving dependencies... (0.1s)

  RepositoryError

  401 Client Error: Unauthorized for url: https://[REDACTED]/artifactory/api/pypi/my-repo/simple/mypackage/

  at ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry/repositories/legacy_repository.py:393 in _get
      389│             if response.status_code == 404:
      390│                 return
      391│             response.raise_for_status()
      392│         except requests.HTTPError as e:
    → 393│             raise RepositoryError(e)
      394│
      395│         if response.status_code in (401, 403):
      396│             self._log(
      397│                 "Authorization error accessing {url}".format(url=response.url),

I searched for similar issues:

But this issue is not the same. In my case Poetry starts to work when I put the repository credentials directly into the pyproject.toml.

[[tool.poetry.source]]
name = "my-repo"
url = "https://<username>:<password>@[REDACTED]/artifactory/api/pypi/my-repo/simple"

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions