27

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

Ed Harrod
  • 3,423
  • 4
  • 32
  • 53
  • Possible duplicate of [Failed to upload packages to PyPI: 410 Gone](https://stackoverflow.com/questions/45207128/failed-to-upload-packages-to-pypi-410-gone) – phd Oct 06 '17 at 14:41
  • Remove `repository` URLs from `~/.pypirc` and try `twine upload` again. – phd Oct 06 '17 at 14:42
  • @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 question – Ed Harrod Oct 06 '17 at 14:46
  • @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 issue – Ed Harrod Oct 06 '17 at 14:48

14 Answers14

16

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/

Ed Harrod
  • 3,423
  • 4
  • 32
  • 53
  • 2
    Hi! I followed your answer, but when I run `twine upload dist/*`, I get:`HTTPError: 403 Forbidden from https://upload.pypi.org/legacy/ Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for more information.`. Can you tell me what's wrong? Thanks. – Red Nov 21 '20 at 16:48
  • @AnnZen assuming you checked the suggestions on https://pypi.org/help/#invalid-auth, do you get the same error with you original account? – Ed Harrod Nov 23 '20 at 09:51
12

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.

Gru
  • 817
  • 13
  • 20
Kevin
  • 403
  • 9
  • 22
  • 12
    This is *very* dangerous. Anyone who has access to your command line history will be able to see your password. – nz_21 Feb 02 '20 at 13:15
  • 1
    Who can access .zsh_history, who can also access .pypirc – OpenThread Jul 25 '22 at 11:13
  • Thank you very much! Indeed, it seems to be a bug from twine, which I'd need to see its code in order to understand exactly why. For now, your solution really has helped me! – Gabriel Lopes Aug 22 '22 at 18:42
8

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

Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67
  • 1
    [The Python Packaging Guide](https://packaging.python.org/guides/using-testpypi/#using-test-pypi) clarifies that test PyPI uses a *separate* account. – kynan Nov 02 '19 at 17:53
7

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.

Ed Harrod
  • 3,423
  • 4
  • 32
  • 53
  • 1
    This was the case for me! I had let chrome generate a complex password for me that I couldn't type out, but once I switched to something type-able it works as expected. – Jesse Reza Khorasanee Sep 13 '19 at 00:52
5

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.

thclark
  • 4,784
  • 3
  • 39
  • 65
  • 1
    [The Python Packaging Guide](https://packaging.python.org/guides/using-testpypi/#using-test-pypi) clarifies that test PyPI uses a *separate* account. – kynan Nov 02 '19 at 17:53
  • Thank you kynan. Whether it was missing or I missed it, I don't know, but that fills in part of the puzzle. (I mean, terrible UX! But hey.). – thclark Nov 04 '19 at 09:03
2

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

Ulf Aslak
  • 7,876
  • 4
  • 34
  • 56
2

On Mac or Linux on terminal vim ~/.pypirc

and add your info:

[server-login]
repository: https://pypi.python.org/pypi
username: <username>
password: <password>
Vishrant
  • 15,456
  • 11
  • 71
  • 120
1

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

caxefaizan
  • 153
  • 11
  • 1
    How does this answer the question? give more details. – Sayed Sohan Aug 12 '20 at 10:38
  • 1
    this solution is intended for the following error....HTTPError: 403 Client Error: Invalid or non-existent authentication information... if you have already created the package and using twine to upload the package and getting this error, typing in manually the API key as password solves the problem. if you want to make a package from beginning. try following this guide. https://medium.com/@faizanzahid09/how-to-create-a-python-package-in-minutes-19f902a61b19 – caxefaizan Aug 13 '20 at 11:03
  • Ridiculous but this worked for me. I ended up deleting the old token and making new one; this one let me copy/paste it without typing manually. – smörkex Jun 18 '21 at 23:10
1

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

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/*
diogo
  • 525
  • 1
  • 7
  • 12
0

Well, I find this is silly but here's a inefficient solution that I used to upload mine.
Type something like this in your editor

__token__
yourTokenHere

And paste it on username field using Ctrl + V
Also, I find Windows + V useful to get my clipboard history.

Neuron
  • 5,141
  • 5
  • 38
  • 59
0

Had the same issues. I was entering my computer username and password. You need to enter PyPi username and password (:

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 07 '22 at 09:19
  • Please consider providing the command that worked for you. It will be easy to understand. – Azhar Khan Nov 08 '22 at 14:27
0

You have to create an account under https://test.pypi.org/account/register/. it looks exactly the same but it use a different database as the pypi.org

ben othman zied
  • 176
  • 1
  • 7
-1

I upload a project but when i view on pypi site, it was missing readme.md file. I didn't know how to update so i deleted the project, accept some warnings though. Lastly, I added readme.md file and tried to upload project again but I got this error. So, i headed to pypi site and completely deleted the last project i uploaded. After then i was able to upload with the same account. Hope this works