Reputation: 29
Below Terminal Logs for your reference
Traceback (most recent call last):
File "src/Utilities_test/test_cases_csv.py", line 39, in <module>
report_status = email_reporter(html_report_dir.split('/', 1)[-1])
File "src/Utilities_support/report_email.py", line 27, in email_reporter for item in conf_data.items(conf):
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/configparser.py", line 857, in items
return [(option, value_getter(option)) for option in d.keys()]
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/configparser.py", line 857, in <listcomp>
return [(option, value_getter(option)) for option in d.keys()]
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/configparser.py", line 854, in <lambda>
section, option, d[option], d)
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/configparser.py", line 394, in before_get
self._interpolate_some(parser, option, L, value, section, defaults, 1)
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/configparser.py", line 444, in _interpolate_some
"found: %r" % (rest,))
configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%'
Upvotes: 2
Views: 8023
Reputation: 377
I recently ran into this because I was passing a dict with preset values into my config parser. Some of the values had a % character. I fixed it by looping over the values and replacing occurrences of % with %%
My problem:
config = configparser.ConfigParser(os.envion)
My solution:
env = os.environ.copy()
# sanitize env, % is config parser special char, escape with %%
for k, v in env.items():
if '%' in v:
env[k] = v.replace('%', '%%')
config = configparser.ConfigParser(env)
Upvotes: 0
Reputation: 21
Try config = configparser.RawConfigParser()
instead of config = configparser.ConfigParser()
. Source: https://programmerah.com/configparser-interpolationsyntaxerror-must-be-followed-by-or-found-27394/
Upvotes: 2
Reputation: 194
Most likely the configparser is reading a literal '%' sign in a string. The '%' sign is used for string interpolation (substitution). If you want to have a literal '%' it can be escaped with another '%'. For example, use '100%%' to represent '100%' in the configuration variable read by configparser.
Upvotes: 5