all Python 3configparserexception
configparser.InterpolationMissingOptionError
exceptions
Raised when a %(name)s or ${section:option} substitution refers to an option that does not exist.
Syntax
except configparser.InterpolationMissingOptionError as e: e.reference
BasicInterpolation looks only in the current section and in [DEFAULT]: %(root)s from a sibling section is not found even if it exists there; that needs ExtendedInterpolation. The reference attribute names the key that was not found.
Examples
import configparser
cfg = configparser.ConfigParser()
cfg.read_string("[common]\nroot = /srv\n[app]\nlogs = %(root)s/logs\n")
try:
cfg.get("app", "logs")
except configparser.InterpolationMissingOptionError as e:
print(e.reference) # → root — в соседнюю секцию %(...)s не заглядывает
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy