poetry: Authentication from poetry.toml doesn't work on 1.1.x
-
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: MacOS 10.15.7
-
Poetry version: 1.1.3
Issue
After upgrade from 1.0.10 to 1.1.3 the authentication for private repositories doesn’t work.
I have an file poetry.toml
with this content:
[repositories]
[repositories.MyPrivateFeed]
url = "https://my-private-repo/pypi/simple/"
[http-basic]
[http-basic.MyPrivateFeed]
username = "user"
password = "pass"
And on pyproject.toml
[[tool.poetry.source]]
name = "MyPrivateFeed"
url = "https://my-private-repo/pypi/simple/"
secondary = true
When I try to update/lock/install I get an error:
update
poetry update
Updating dependencies
Resolving dependencies... (0.4s)
RepositoryError
401 Client Error: Unauthorized for url: https://my-private-repo/pypi/simple/mypy/
at ~/.pyenv/versions/3.8.5/envs/my-project/lib/python3.8/site-packages/poetry/repositories/legacy_repository.py:390 in _get
386│ if response.status_code == 404:
387│ return
388│ response.raise_for_status()
389│ except requests.HTTPError as e:
→ 390│ raise RepositoryError(e)
391│
392│ if response.status_code in (401, 403):
393│ self._log(
394│ "Authorization error accessing {url}".format(url=url), level="warn"
lock
poetry lock
Updating dependencies
Resolving dependencies... (0.4s)
RepositoryError
401 Client Error: Unauthorized for url: https://my-private-repo/pypi/simple/mypy/
at ~/.pyenv/versions/3.8.5/envs/my-project/lib/python3.8/site-packages/poetry/repositories/legacy_repository.py:390 in _get
386│ if response.status_code == 404:
387│ return
388│ response.raise_for_status()
389│ except requests.HTTPError as e:
→ 390│ raise RepositoryError(e)
391│
392│ if response.status_code in (401, 403):
393│ self._log(
394│ "Authorization error accessing {url}".format(url=url), level="warn"
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 44
- Comments: 41 (13 by maintainers)
Why this issue is closed? It seems like the fix has not been pushed
I’m also experiencing this same issue
I had the same issue, it works for me when I do the following steps:
pyproject.toml
remove the wordsimple
from the url in[[tool.poetry.source]]
poetry config repositories <REPOSITORY_NAME> <URL>
where url is the same one that you set in[[tool.poetry.source]]
(without the word simple)I also dont understand why this ticket was closed. I had exactly the same problem… In fact, because of this Keyring issue, when installing the public packages, poetry even starts looking first for my private repo, so I started specifying in each dependency, the repo source:
And just after this process, the library tells me the problem is really with the authentication with the private server.
After following the steps provided by @SimonVerhoek everything worked as expected. Also, if one specifies directly in the toml the credentials like this:
it also works, but this is not ideal as no one wants the credentials to be plain text in github.
Another fun fact: I didnt experience this problem neither in MacOS or Docker container. Was really only when I tried in a Linux virtual machine 😕
After trying out everything stated here multiple times without avail and banging my head against the wall over the course of a few days, I finally seem to have a situation working where a poetry project can import a self-made private package published with poetry.
While looking at the
auth.toml
, I noticed that no password was set. It looked like this:Apparently, the password is set in your OS’s native keychain by the library called
keyring
by default. I did the following:keyring
like thispoetry config http-basic.my-package <personal_access_token> <personal_access_token_password>
. This now gave the following messages in return:Poetry’s
auth.toml
now looked like this:…and after running
poetry update
once more, the library installed flawlessly.This worked with
poetry==1.1.11
, installed bybrew
on MacOS. (part of) mypyproject.toml
:Another data point: I could not get @ayalganem55’s steps to work. But what seemed to do the trick was to set
default = true
for the private source. In our case, the private source is an Artifactory which includes a pypi mirror. Preliminary testing suggests that neither settingpoetry config repositories
nor removingsimple
from the URL are required as long asdefault = true
is set. I’m using poetry version1.1.4
.In
pyproject.toml
:Local configuration:
poetry config http-basic.mysource <user> <password>
Well, this issue is closed, but I found my issue which I think may actually be different. I had http-basic setup for the repository for the purpose of posting to it. For our artifactory pypi repository authorization is not needed to get from the repository, only to publish. Therefore, it did not even occur to me that poetry may be using the basic auth credentials for get operations. However, I changed my password so auth failed even for get. I guess that kind of makes sense because poetry doesn’t know how the security is configured on your repo so if you provide a user name and password it just uses it for all operations. Your user name and password should be valid. It just took me longer to troubleshoot because the particular operation I was performing did not actually require authorization so I forgot to check if the credentials themselves are valid. I guess @marcosborges we both solved our respective problems. However, maybe this will help the next person.
I am facing authentication issues with a private repo that doesn’t require authentication. any guidance on how to solve this? 401 Client Error: Unauthorized for url: XXX
Thank you @SimonVerhoek , your steps helped me solve this problem when trying to download packages from AWS CodeArtifact. We are building container images and using Docker secrets to mount the
auth.conf
from the host temporarily into the build environment, which is incompatible with using the OS keyring.I opted to configure the Python keyring with environment variables in our build scripts like this:
I had this issue recently with AWS CodeArtifact and what solved my problem was using these environment variables:
POETRY_HTTP_BASIC_ARTIFACTORY_<AWS_CODEARTIFACT_REPO_NAME>_USERNAME
POETRY_HTTP_BASIC_ARTIFACTORY_<AWS_CODEARTIFACT_REPO_NAME>_PASSWORD
The last one having the same value ofCODEARTIFACT_TOKEN
Um abraço @jairhenrique !I am also experiencing the same issue.
$ poetry config http-basic.fury "<test>" NOPASS
I don’t know if this is the proper fix, but I manually edited
poetry/console/commands/config.py
:Commenting out the
raise ValueError
fixed it for me.A temporary solution that works for me is adding the private repository via
poetry config repositories.<name> <url>