[英]Issue in python code [ configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%' ] using python 3.7.3 with appium
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: '%'
Most likely the configparser is reading a literal '%' sign in a string.很可能 configparser 正在读取字符串中的文字 '%' 符号。 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.例如,在configparser读取的配置变量中使用'100%%'表示'100%'。
Try config = configparser.RawConfigParser()
instead of config = configparser.ConfigParser()
.尝试config = configparser.RawConfigParser()
而不是config = configparser.ConfigParser()
。 Source: https://programmerah.com/configparser-interpolationsyntaxerror-must-be-followed-by-or-found-27394/来源: https : //programmerah.com/configparser-interpolationsyntaxerror-must-be-followed-by-or-found-27394/
I recently ran into this because I was passing a dict with preset values into my config parser.我最近遇到了这个问题,因为我将带有预设值的 dict 传递到我的配置解析器中。 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.