15
votes

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

9
Remove repository URLs from ~/.pypirc and try twine upload again.phd
@phd Thanks but I've tried this, as I said "I've also tried doing the same but with the repository line removed." in my questionECH
@phd - not a duplicate, as the error returned from Twine is different. In addition, I have tried the solutions suggested already, and they don't solve my issueECH

9 Answers

7
votes

EDIT: if you're using Windows, check my other suggestion

It looks like some sort of error with the account I was using. The following steps fixed it for me:

  1. Create a new account
  2. Upload the package with the new account with twine upload dist/*
  3. Add the previous account (that you originally wanted to upload with) to the package as an owner

Also 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/

6
votes

When we enter the password, the password is not wrong, and I think it's a bug.

I use -u for the username and -p for the password directly without using the fields provided by the console(the default).

I try to run this in the command: twine upload -u YOUR-USERNAME -p YOUR-PASSWORD --repository-url https://test.pypi.org/legacy/ dist / *

I run that command on windows: command-picture

It works for me. Hope this will help

5
votes

I hit this problem following the pypi instructions for creating a new package. That tutorial takes you through uploading to their test server (--repository-url https://test.pypi.org/legacy/), for which I always get a 403.

For 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.

4
votes

PyPi and TestPyPi are separate instances of the package index which have separate user databases. Therefore, separate accounts must be created.

Maybe 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.

(Grumble, grumble, zen of python, grumble....)

4
votes

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.

EDIT: it looks like this is a known issue with pasting on Windows, see suggestion on https://pypi.org/help/#invalid-auth:

If 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.

2
votes

I had the same problem. What worked for me was to (1) add a new email, verify it and make it primary.

1
votes

Type in the password manually. Seems dumb but it worked for me.

1
votes

I was getting the same error in my ubuntu 20.04 machine. From this i have figured out something that

  • I was using vs code integrated terminal and it was using zsh not bash

Then i use my system terminal and it worked fine for me.

Also make sure you have configured your setup.py properly.

1
votes

Having verified accounts in PyPI and TestPyPI with credentials (usr1, pwd1) and (usr2, pwd2) respectively, contents for ~/.pypi:

[distutils]
index-servers=
    pypi
    testpypi

[pypi]
repository: https://upload.pypi.org/legacy/
username: usr1
password: pwd1

[testpypi]
repository: https://test.pypi.org/legacy/
username: usr2
password: pwd2

After building the package, publishing for TestPyPI:

twine upload --repository testpypi dist/*

Publishing for PyPI:

twine upload --repository pypi dist/*