Can't upload to PyPi with Twine

Question:

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

Asked By: Ed Harrod

||

Answers:

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/

Answered By: 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.

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.

Answered By: Ed Harrod

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

Answered By: Ulf Aslak

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.

Answered By: thclark

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

Answered By: Lorem Ipsum

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.

Answered By: Kevin

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

Answered By: caxefaizan

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.

Answered By: Mehedi Hasan Shifat

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/*
Answered By: diogo

I upload a project but when i viewed on pypi site, it wasn missing readme.md file. I wasn’t knowing 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

Answered By: Seyed Muzaffar

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.

Answered By: sunil swain

On Mac or Linux
on terminal
vim ~/.pypirc

and add your info:

[server-login]
repository: https://pypi.python.org/pypi
username: <username>
password: <password>
Answered By: Hanany Tolba

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

Answered By: Raad Dego
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.