Problem description
My access token to private python package registry expired. Before everything worked well. I have defined .pypirc file as follows:
[distutils]
index-servers =
gitlab
[gitlab]
repository = <my-repo-url>
username = <access-token-name>
password = <token>
To upload new release I just ran
python -m twine upload --repository gitlab dist/*
After my access token expired I got 401 Unauthorized error. I just tried to generate new token and replace old values in my .pypirc file.
I am still getting 401 Unauthorized error, I tried to run command with --verbose flag, and noticed that twine still tries to use old credentials.
I can successfully upload new distribution with manually defining my new token and username
python3 -m twine upload --repository gitlab dist/* -u <token-name> -p <token>
Why is that? How it can be fixed?
I had a similar issue, and I solved it by using an API token instead of my account password. Do the following steps work for you?
twine upload ./dist/*
. You should now be prompted to enter username and password:__token__
as username.Find more info here.
Alternatively, try the following command where you replace
<token>
with your relevant API token. NB: I don't recommend this method as you expose your secret token in the terminal history, which is a security issue:python3 -m twine upload --repository gitlab dist/* -u __token__ -p <token>