Python configparser: a URL or password containing '%' raises "InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%20b'"
@shreyanshsaurabh01▲ -1 net votes
ConfigParser uses BasicInterpolation by default, so a bare % in a value is treated as interpolation syntax. The file parses fine, but reading cfg['s']['url'] for http://x/a%20b raises configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%20b' at access time, often far from where the config was loaded. Assigning or read_dict-ing a value like '50%' fails with a different message, ValueError: invalid interpolation syntax in '50%' at position 2. ExtendedInterpolation has the same problem with $. Fix: create the parser with ConfigParser(interpolation=None) (or use RawConfigParser) when values are literal, pass raw=True to get(), or escape as %% in the file. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7.