This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Configparser interpolation is unexpected
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: lukasz.langa Nosy List: jens, lukasz.langa, martin.panter, tbekolay
Priority: normal Keywords:

Created on 2015-04-30 19:12 by tbekolay, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg242283 - (view) Author: Trevor Bekolay (tbekolay) Date: 2015-04-30 19:12
I was having an issue installing a package in Python 3, which installed properly in Python 2. This is the error message I got:

    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

    ... snip unhelpful traceback ...

      File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/configparser.py", line 423, in _interpolate_some

        "found: %r" % (rest,))

    configparser.Interpolation

    ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/12/p4ngkfbx2pnb1ln81csjb19c0000gn/T/pip-build-6xhgg5x6/nengo

This wasn't a super helpful error message. I managed to figure out that Python 3 (or setuptools?) was attempting to parse my ~/.pypirc file, which raised a configparser.InterpolationSyntaxError because my password contained a percent-sign. Configparser doesn't try to interpolate this string in Python 2, so it worked fine. As a workaround, I've changed my PyPI password, but this failure was quite surprising to me.

As for what I would expect to happen, I would not expect interpolation to happen if I don't want it to happen. All of the examples shown on in the docs use the syntax "%(key)s" or "${key}". If this is the only way to interpolate, then why is "%" ambiguous? Surely we can look forward one character, and if it's not "(" then "%" should be interpreted literally. Instead, configparser requires me to disambiguate with "%%". But, this would cause my string to be parsed incorrectly in Python 2's configparser, so I'm unable to make that change.
msg242292 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2015-04-30 23:17
This is expected behaviour but I agree the error message should be improved. There are people using interpolation in .pypirc, if you don't want that, just use a double % sign and it will do the right thing. You don't have to change your password.

I'll leave that open to find what's the source of the exception and maybe add a more helpful message there.
msg242564 - (view) Author: Trevor Bekolay (tbekolay) Date: 2015-05-04 17:09
Thanks for the quick response! I can see the use case for using interpolation in .pypirc. Unfortunately for me, I push releases for both Python 2 and Python 3, so having the double percent sign will cause problems for me on Python 2.

The exception that's being raised is at line 442 (https://hg.python.org/cpython/file/default/Lib/configparser.py#l442). The message itself seems to have the right information, but setuptools seems to mangle it  (perhaps InterpolationSyntaxError needs a __repr__ or __str__?)
msg245120 - (view) Author: Jens Diemer (jens) Date: 2015-06-10 07:45
IMHO i ran into the same bug, try to "./setup.py upload" with my new password in ~/.pypirc:

    configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: "%foobar"

This is a limitation of the configparser... But what's about to validate this on the "set PyPi password view" ?

So that's impossible to set a PyPi password which can't be parsed by configparser ?
msg268308 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2016-06-12 01:12
This is solved upstream in setuptools by disabling configparser interpolation.
History
Date User Action Args
2022-04-11 14:58:16adminsetgithub: 68274
2016-06-12 01:12:50lukasz.langasetstatus: open -> closed
resolution: not a bug
messages: + msg268308
2015-09-04 17:43:24lukasz.langasetassignee: lukasz.langa
2015-06-10 07:45:49jenssetnosy: + jens
messages: + msg245120
2015-05-13 04:30:33martin.pantersetnosy: + martin.panter
2015-05-04 17:09:03tbekolaysetmessages: + msg242564
2015-04-30 23:17:09lukasz.langasetmessages: + msg242292
2015-04-30 21:56:33ned.deilysetnosy: + lukasz.langa

versions: + Python 3.5, - Python 3.2, Python 3.3
2015-04-30 19:12:10tbekolaycreate