Skip to content

Authentication to private registry fails #9910

Description

@sr-verde

Description

I use Poetry with a private package registry (a self-hosted Gitlab). I just needed to update my access token and did so using:

poetry config http-basic.myregistry __token__ glpat-<redacted_token>

This works fine. I can see the token in my keyring and when deactivating the keyring (in ~/.config/pypoetry/config.toml) I can see the token in the auth.toml config file. But my registry denies access to it with a status code 401.

I changed the token, used another user’s token, used a group access token… Nothing worked. So I dove into the Poetry code and added some print statements to the Authenticator.request function. I added a print(prepared_request.headers). What I can see, is that Poetry is using the old and expired token.

I was able to locate the problem in prepared_request = session.prepare_request(request). request has the correct credentials but prepared_request has the old ones.

I am not sure if this is an issue with Poetry or with requests. I did not fully understand where the old token is still stored.

Workarounds

I looked into the prepare_request function (which is part of requests). As a workaround, authentication works when I remove these lines:

        if self.trust_env and not auth and not self.auth:
            auth = get_netrc_auth(request.url)

Poetry Installation Method

system package manager (eg: dnf, apt etc.)

Operating System

Arch

Poetry Version

1.8.4

Poetry Configuration

cache-dir = "/home/user/.cache/pypoetry"
experimental.system-git-client = false
installer.max-workers = null
installer.modern-installation = true
installer.no-binary = null
installer.parallel = true
keyring.enabled = true
repositories.myregistry.url = <REDACTED>
solver.lazy-wheel = true
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{project_name}-py{python_version}"
warnings.export = true

Python Sysconfig

No response

Example pyproject.toml

No response

Poetry Runtime Logs

$ poetry lock
Updating dependencies
Resolving dependencies... (1.4s)Source (myregistry): Authorization error accessing https://REDACTED/api/v4/groups/42/-/packages/pypi/simple/package1/
Resolving dependencies... (1.6s)Source (myregistry): Authorization error accessing https://REDACTED/api/v4/groups/42/-/packages/pypi/simple/package2/
Resolving dependencies... (3.3s)Source (myregistry): Authorization error accessing https://REDACTED/api/v4/groups/42/-/packages/pypi/simple/package1/
Resolving dependencies... (3.4s)Source (myregistry): Authorization error accessing https://REDACTED/api/v4/groups/42/-/packages/pypi/simple/package2/
Resolving dependencies... (5.5s)Source (myregistry): Authorization error accessing https://REDACTED/api/v4/groups/42/-/packages/pypi/simple/package1/
Resolving dependencies... (5.7s)Source (myregistry): Authorization error accessing https://REDACTED/api/v4/groups/42/-/packages/pypi/simple/package2/
Resolving dependencies... (6.2s)Source (myregistry): Authorization error accessing https://REDACTED/api/v4/groups/42/-/packages/pypi/simple/package1/
Resolving dependencies... (6.3s)Source (myregistry): Authorization error accessing https://REDACTED/api/v4/groups/42/-/packages/pypi/simple/package2/
Resolving dependencies... (6.7s)

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expectedstatus/triageThis issue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions