Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have gone through already available answers in SO but nothing seems working for me.

I am following python commands to upload my package(Note: I am a new user and have registered the account with username and password):

Create setup.py:

from setuptools import setup

setup(
    name='',  # This is the name of your PyPI-package.
    version='0.1',  # Update the version number for new releases
    scripts=['']  # The name of your script, and also the command you'll be using for calling it
)

Package the script:

python setup.py sdist

Register the account:

python setup.py register

This prompted me below message(I choose 2nd as I am new user):

1. use your existing login,
2. register as a new user,
3. have the server generate a new password for you (and email it to you), or
4. quit
Your selection [default 1]:

Upload the package:

python setup.py sdist upload

After trying steps I got the error while uploading:

Upload failed (403): Invalid or non-existent authentication information.
error: Upload failed (403): Invalid or non-existent authentication information.
like image 508
Jitesh Mohite Avatar asked Apr 12 '18 04:04

Jitesh Mohite


4 Answers

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/*
like image 197
Jitesh Mohite Avatar answered Nov 03 '22 00:11

Jitesh Mohite


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.

like image 38
hoefling Avatar answered Nov 03 '22 01:11

hoefling


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

like image 29
Roushan Avatar answered Nov 03 '22 00:11

Roushan


To change to the new PyPI authentication method, go to https://pypi.org/manage/account/token/

Login to your account and you'll see

enter image description here

Give the token a name, select the Scope (i.e. what repository do you allow the Token to be used for).

Then copy the token as the password in your ~/.pypirc file, use __token__ as the username, e.g.

[distutils]
index-servers =
    pypi
    testpypi

[pypi]
username: __token__
password: pypi-12837192048i1234...
like image 38
alvas Avatar answered Nov 03 '22 01:11

alvas