Not able to upload package in https://upload.pypi.org/legacy/

After a lot of trial and error, I found the simple solution. Also, @hoefling answer helps me to solve them.

Register as a user in https://pypi.org/ and use register account command which mentioned in the question.

Now, Three magic steps which will resolve the issue.

pip install twine

python setup.py sdist

# This will ask for you username and password
twine upload dist/*

EDIT:

If you want to upgrade your package, just follow the below simple steps:

  1. Delete the build, dist, and <package name>.egg-info folders in your root directory.
  2. Change the version number in your setup.py file.
  3. Create distribution again. e.g: python setup.py sdist bdist_wheel
  4. Upload distribution again. e.g: twine upload dist/*

First of all, note that register is deprecated and not necessary anymore. When trying to register a package on PyPI, you should get a message:

Server response (410): This API is no longer supported, instead simply upload the file.

Just skip the register step and proceed with the uploading.

distutils/setuptools

Create a file $HOME/.pypirc with the contents:

[distutils]
index-servers =
    pypi

[pypi]
username: <username>
password: <password>

and repeat the upload:

$ python setup.py sdist upload

Thing is, the distutils' upload subcommand doesn't provide an option to enter the credentials from command line, instead completely relying on the .pypirc file.

twine

If storing credentials in plain text format is not your thing, twine provides a possibility of entering credentials from command line. This is also the officially recommended tool for uploading packages.

  1. Install twine:

    $ pip install twine
    
  2. Build the package:

    $ python setup.py clean sdist
    
  3. Upload:

    $ twine upload dist/*
    

    The tool will ask you for the username and password.

twine also lets you provide the credentials in environment variables:

$ TWINE_USERNAME=me TWINE_PASSWORD=passwd twine upload dist/*

or via keyring.


Create a file in home dir by touch ~/.pypirc similar look like: added pytest optionally

[distutils]
index-servers =
  pypi
  pypitest

[pypi]
repository=https://pypi.python.org/pypi
username=your_username
password=your_password

[pypitest]
repository=https://testpypi.python.org/pypi
username=your_username
password=your_password

Things to care about the following error

403: Invalid or non-existent authentication information

  • If there is a % in your password just type it without escaping; e.g. Hello%123

  • If there is a space character in your password just type it without quotes; e.g. Hello 123

Register your package against PyPI's server

python setup.py register -r pypi

Upload your package

python setup.py sdist upload -r pypi

From official doc

First, you need a PyPI user account