pypirc – Fix Breaks Login
(When an upstream bugfix breaks my login)
Getting started on the Python Package Index
Back when I was finally willing to release python code to the wild I did some reading on the web of the simplest methods of getting a project uploaded to PyPI. I found several resources, but one that I clipped and still occasionally refer to was a simple article by Peter Downs on making a project pip installable that is hosted on Github.
This was very simple to follow, so I registered with PyPI (and TestPyPI) using a password generator and created my .pypirc
file. After fleshing out my project and adding the necessary components to the setup.py
file I excitedly tried to register and upload my first project.
X% of the way there…
However, on trying to register and upload my project I was getting major looking failures, with a stack trace pointing ultimately to a line like:
configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: …
The google gods were smiling that day as someone else had come across the same issue and filed a bug report on the PyPI Github account, and a bit of extra digging led me to realise that % signs in pypirc passwords would need to be escaped by doubling them.
Moving forward 2 years
Now in the present, I was going to try and upload an updated version of a project, but from my home PC. The setuptools
process proceeded as planned until the very end when it threw the following error:
Upload failed (401): You must be identified to edit package information
This seemed strange so I checked my pypirc file, which looked in order. I also manually logged into the PyPI and TestPyPI site, which worked fine so my credentials were fine.
This was, unfortunately, a bit harder to track down as the error string had multiple causes. StackOverflow had questions here and here, and Reddit had a thread here but they all lead nowhere for me.
Going back to first principles
If my creds are fine then perhaps something had corrupted my pypirc file, so I grabbed my passwords and recreated my pypirc file. In this process, I noticed (and remembered) the double % signs from 2 years ago – so using an educated guess recreated without this fix implemented.
Success! I had now successfully uploaded my new code. Investigating further I rediscovered the bug report I came across 2 years prior and noticed it had been updated relatively recently with new information. Apparently, the upstream cpython code for distutils
had been updated to fix a bug introduced in Python3 and added to python3.5
.
Leave a Reply