HTTP basic auth for pulling from private repositories does not work
See original GitHub issue- 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"
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
Troubleshooting errors with Docker commands when using ...
If you are running docker pull on an Amazon EC2 instance in a private ... HTTP 403 Errors or "no basic auth credentials"...
Read more >Fetch private repo using Github API by Basic Auth
Authenticating with client_id and client_secret doesn't authenticate you as a user; it just identifies the application.
Read more >Pull an Image from a Private Registry - Kubernetes
A Kubernetes cluster uses the Secret of kubernetes.io/dockerconfigjson type to authenticate with a container registry to pull a private image.
Read more >Private Repository Authentication :: Antora Docs
Antora can authenticate with private repositories using HTTP Basic authentication. HTTP Basic authentication requires sending credentials to the server ...
Read more >Gitlab runner fails to connect to private registry with 'no basic ...
Gitlab runner fails to connect to private registry with 'no basic auth credentials' even when DOCKER_AUTH_CONFIG is set.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@javier-panichelli, here you go. It’s not a bug or anything like that, I just did not understand how Poetry handles it.
In the
pyproject.toml
:What is important is the
name
of the repo. It can probably be whatever you want, but I only tried letters and underscores.To inject credentials for example via environment variables the variable names must contain the
name
in uppercases separated by underscores. So in the example:Thank you a lot for your answer! I noted that I was using
_USER=
instead of_USERNAME
That didn’t make it work, but after I added a single letter to the source name (and its variables counterparts), it worked! Not sure why, though…
UPDATE: It will work if I use different names for env variables/name tag combo and poetry config http-basic._ command
[pyproject.toml]
[[tool.poetry.source]]
name = "xyz"
poetry config http-basic.abc $POETRY_HTTP_BASIC_xyz_USERNAME $POETRY_HTTP_BASIC_xyz_PASSWORD -vvv