Home:ALL Converter>Can't upload to PyPi with Twine

Can't upload to PyPi with Twine

Ask Time:2017-10-06T21:18:51         Author:Ed Harrod

Json Formatter

I'm trying to upload a python package to PyPi, using the following commands:

pip install -e .
python setup.py bdist_wheel --universal
twine upload --repository-url https://upload.pypi.org/legacy/ dist/*

I get this error:

HTTPError: 403 Client Error: Invalid or non-existent authentication information. for url: https://upload.pypi.org/legacy/

I've also tried the following commands:

twine upload dist/*
twine upload --repository-url pypi dist/*
twine upload --repository-url https://upload.pypi.org/legacy dist/*
python setup.py bdist_wheel --universal upload

with a .pypirc file located in the same directory I'm running the commands from which is:

[distutils]
index-servers =
    pypi
    pypitest

[pypitest]
repository: https://testpypi.python.org/pypi/
username: <username>
password: <password>

[pypi]
repository: https://upload.pypi.org/legacy/
username: <username>
password: <password>

But I'm still asked for my password. (Also tried this using pypitest, after creating an account on there too, but get the same error)

I've also tried doing the same but with the repository line removed.

The package name I'm trying to upload used to be occupied, but it has been removed now - https://pypi.python.org/pypi?name=&version=1.0.0&:action=display says that the package is not found

The username and password I'm using are the same I use to successfully log in to https://pypi.python.org/pypi?%3Aaction=login_form

Author:Ed Harrod,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/46606692/cant-upload-to-pypi-with-twine
Ed Harrod :

An alternative could have been that copying and pasting wasn't working - when I try to paste the password in the command line it showed this error, but when I typed it out manually it succeeded.\nEDIT: it looks like this is a known issue with pasting on Windows, see suggestion on https://pypi.org/help/#invalid-auth:\n\nIf you're using Windows and trying to paste your password or token in the Command Prompt or PowerShell, note that Ctrl-V and Shift+Insert won't work. Instead, you can use "Edit > Paste" from the window menu, or enable "Use Ctrl+Shift+C/V as Copy/Paste" in "Properties". This is a known issue with Python's getpass module.\n",
2017-10-17T13:31:56
thclark :

I hit this problem following the pypi instructions for creating a new package. That tutorial takes you through uploading to their test server\n(--repository-url https://test.pypi.org/legacy/), for which I always get a 403.\n\nFor their actual uploads server, (--repository-url https://upload.pypi.org/legacy/) my credentials work fine. So clearly there's some variation in credentials between their test and live servers, which could be worth considering if you're bumping against this problem.",
2019-04-02T10:01:02
Ulf Aslak :

I had the same problem. What worked for me was to (1) add a new email, verify it and make it primary.",
2019-03-15T21:35:55
Hanany Tolba :

On Mac or Linux\non terminal\nvim ~/.pypirc\nand add your info:\n[server-login]\nrepository: https://pypi.python.org/pypi\nusername: <username>\npassword: <password>\n",
2022-06-05T10:13:20
caxefaizan :

Type in the password manually. Seems dumb but it worked for me.",
2020-08-12T08:58:53
Mehedi Hasan Shifat :

I was getting the same error in my ubuntu 20.04 machine. From this i have figured out something that\n\nI was using vs code integrated terminal and it was using zsh not bash\n\nThen i use my system terminal and it worked fine for me.\nAlso make sure you have configured your setup.py properly.",
2021-01-14T14:41:53
diogo :

Having verified accounts in PyPI and TestPyPI with credentials (usr1, pwd1) and (usr2, pwd2) respectively, contents for ~/.pypi:\n[distutils]\nindex-servers=\n pypi\n testpypi\n\n[pypi]\nrepository: https://upload.pypi.org/legacy/\nusername: usr1\npassword: pwd1\n\n[testpypi]\nrepository: https://test.pypi.org/legacy/\nusername: usr2\npassword: pwd2\n\nAfter building the package, publishing for TestPyPI:\ntwine upload --repository testpypi dist/*\n\nPublishing for PyPI:\ntwine upload --repository pypi dist/*\n",
2021-04-12T21:32:04
Ed Harrod :

EDIT: if you're using Windows, check my other suggestion\nIt looks like some sort of error with the account I was using. The following steps fixed it for me:\n\nCreate a new account\nUpload the package with the new account with twine upload dist/*\nAdd the previous account (that you originally wanted to upload with) to the package as an owner\n\nAlso be aware that the test pypi server --repository-url https://test.pypi.org/legacy/, requires a different account to be created from the live server --repository-url https://upload.pypi.org/legacy/",
2017-10-09T10:30:02
sunil swain :

Well, I find this is silly but here's a inefficient solution that I used to upload mine.\nType something like this in your editor\n__token__\nyourTokenHere\n\nAnd paste it on username field using Ctrl + V\nAlso, I find Windows + V useful to get my clipboard history.",
2021-08-19T13:12:43
Kevin :

When we enter the password, the password is not wrong, and I think it's a bug.\nI use -u for the username and -p for the password directly without using the fields provided by the console(the default).\nI try to run this in the command:\ntwine upload -u YOUR-USERNAME -p YOUR-PASSWORD --repository-url https://test.pypi.org/legacy/ dist/*\n\nI run that command on windows:\n\nIt works for me. Hope this will help.",
2019-11-05T17:42:23
Raad Dego :

Had the same issues.\nI was entering my computer username and password.\nYou need to enter PyPi username and password (:",
2022-11-03T21:48:44
Lorem Ipsum :

PyPi and TestPyPi are separate instances of the package index which have separate user databases. Therefore, separate accounts must be created. \n\nMaybe you'll get lucky and the test account name won't be taken and you can use the same commands in test as in production.\n\n(Grumble, grumble, zen of python, grumble....)",
2019-08-02T16:06:20
yy