46

When running..

python setup.py sdist register upload

..I get the following output:

running register
We need to know who you are, so please choose either:
 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]:  1
Username: example
Password: ...
Registering mypackage to http://pypi.python.org/pypi
Server response (200): OK
I can store your PyPI login so future submissions will be faster.
(the login will be stored in /Users/dbr/.pypirc)
Save your login (y/N)?y
running upload
Submitting dist/mypackage-1.2.1.tar.gz to http://pypi.python.org/pypi
Upload failed (401): You must be identified to edit package information

It's prompting to save the login details, despite ~/.pypirc already containing this. It then fails to upload files for a package I own, and have full write-access to.

dbr
  • 165,801
  • 69
  • 278
  • 343

7 Answers7

60

Just found this page, which solves the issue:

I also noticed that while it was asking me to save my login information, and I hit Y everytime, it still asked me for the username and password. It turned out that it was saving the information incorrectly as follows:

[pypi]
username:dcramer
password:*******

Changing it out to this solved the problems:

[server-login]
username:dcramer
password:********

The above content goes into the .pypirc file in the user's home directory.

Ugh.. I think this may be a good time to give distribute a try..

bignose
  • 30,281
  • 14
  • 77
  • 110
dbr
  • 165,801
  • 69
  • 278
  • 343
  • This fix worked for me too, thanks. Looks like a bug in distutils? – Chris Miles Mar 31 '10 at 05:52
  • @Chris Quite likely.. Haven't noticed it lately (might be fixed), but I haven't been using distutils much recently – dbr Mar 31 '10 at 09:56
  • I just spent 2+ hours chasing ghosts and got to watch the sun rise through my office window because of fallout from this ridiculous bug. I am on Python 2.6 btw. – dkamins Jun 09 '11 at 12:36
  • 1
    distribute doesn't help, I encounter same problem with distribute with Python2.7 – Fang-Pen Lin Jul 14 '11 at 07:52
  • 2
    Where is that file in which it saves this info? (on Windows?) – Craig McQueen Jul 11 '12 at 03:58
  • @CraigMcQueen Not sure, but try checking in wherever `os.path.expanduser("~")` shows, or maybe `os.environ['APPDATA']`? – dbr Jul 12 '12 at 17:03
  • 2
    The file is .pypirc, I found it in the root of my Users folder on Windows (which corresponded to `os.path.expanduser("~")`) but adding the info there didn't fix anything. Removing the [pypi] section caused an error in ConfigParser. Fixed it per [this question](http://stackoverflow.com/questions/3773613/pypi-issues-upload-failed-401-you-must-be-identified-to-edit-package-inform): you need a HOME environment variable on Windows that points to the file's folder. – Tom Nov 12 '12 at 17:11
  • 4
    The file this is in (for me) was `~/.pypirc`. Might be helpful to note. – Patrick Perini Feb 25 '13 at 03:53
  • In Windows, if you use Notepad to create the .pypirc file, it will automatically save as `.pypirc.txt`. Use the command line to rename it to `pypirc' without an extension. – Eric W. Aug 20 '14 at 19:38
  • I went round and round with this before finally discovering by accident that HOME was not set to the place it was supposed to be. So I had 2 .pypirc files, one in the place I "knew" was my home folder, because that's the way I set all my machines, and the one that was actually set. The one `python setup.py` was finding was the wrong one. :-/ – matt wilkie Nov 26 '14 at 05:36
  • 1
    Are you saying I need to store my password in plain text in a file? – cs01 Nov 07 '16 at 02:52
19

None of the changes to ~/.pypirc listed here worked for me.

This worked for me, with no changes to ~/.pypirc. I added "-r https://www.python.org/pypi" to the command line:

python setup.py register sdist upload -r https://www.python.org/pypi

My ~/.pypirc looks like this

[distutils]
index-servers: pypi

[pypi]
username: dlink
password: ******** (the real one)
dlink
  • 1,489
  • 17
  • 22
4

I have the same problem, This is my solution.

The python version is 2.7.7, my windows version is Windows-7-6.1.7601-SP1.

here is my .pypirc file

[distutils]
index-servers=pypi

[pypi]
repository = https://pypi.python.org/pypi

[server-login]
username = user
password = password

Notice:

In windows, A file is not allowed named as “.pypirc”,plz,refer to:

Rename files to empty filename in Windows

Then put you ".pypirc" file in the same folder with "setup.py"

At last:

run :

python setup.py sdist upload

or:

python setup.py sdist register upload

I hope this will be help,thank you!

Community
  • 1
  • 1
kongyue
  • 61
  • 4
1

I have this problem and solved it by putting the file .pypirc under my home directory (~/), as the last past of the first comment suggests.

I didn't have the need to modify the name of the section "pypi" of the file pypirc for "server-login", as suggested also in the first comment.

Jasg
  • 78
  • 4
0

I changed [distutils] to [pypirc] as per the docs and this worked for me.

Here is my ~/.pypirc file:

[pypirc]
index-servers =
    pypi
    pypitest

[pypi]
repository=https://pypi.python.org/pypi

[pypitest]
repository=https://testpypi.python.org/pypi

[server-login]
username:stav
password:****
Steven Almeroth
  • 7,758
  • 2
  • 50
  • 57
0

I had this problem, due to my own fault but hopefully this may help someone else who makes this same mistake.

I'm using python 3 on Linux Ubuntu, during registration I issued the setup command using sudo! The result was the .pypirc file in my home directory was owned by root and wasn't readable when trying to perform a module upload immediately after as a none privileged user.

By changing the ownership of the file to myself, the issue was resolved.

Mortoman
  • 139
  • 3
  • 7
-1

I ran into the same problem. I'm on a new OS X Sierra. Adding [server-login] entry to ~/.pypirc seemed to fix it

http://www.seanbehan.com/how-to-fix-pypi-upload-failed-403-invalid-or-non-existent-authentication-information/

seanbehan
  • 1,463
  • 15
  • 23