all Python 3configparserexception
configparser.InterpolationSyntaxError
exceptions
Raised when a value contains % (or $ with extended interpolation) that is not followed by a valid reference.
Syntax
except configparser.InterpolationSyntaxError as e: ...
The usual case is '50%', a URL with %20 or a password with a percent sign in the INI file. The file reads without errors and get() fails. Fix it by doubling %% in the file, with get(..., raw=True) or with ConfigParser(interpolation=None). Writing the same string with set() raises ValueError, not this exception.
Examples
import configparser
cfg = configparser.ConfigParser()
cfg.read_string("[web]\nurl = /a%20b\n")
try:
cfg.get("web", "url")
except configparser.InterpolationSyntaxError as e:
print(e) # → '%' must be followed by '%' or '(', found: '%20b'
print(cfg.get("web", "url", raw=True)) # → /a%20b
import configparser
cfg = configparser.ConfigParser()
cfg.add_section("web")
try:
cfg.set("web", "rate", "5%")
except ValueError as e:
print(type(e).__name__) # → ValueError
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy