I'm trying to parse a .conf file with ConfigParser, and some of the values have a '%' in the value.
Example of the config below:
[global]
workgroup = WORKGROUP
server string = %h server (Samba, Ubuntu)
When I parse this using RawConfigParser, it sets server string to
%h server (Samba, Ubuntu)\n\n\n\ndns proxy = no\n\n\n\n\n\n\n\n...REST_OF_CONFIG_SECTION
Where the bunch of \n are blank lines between config options. And when I use the normal ConfigParser, I get an InterpolationSyntaxError with the error
'%' must be followed by '%' or '(', found: '%h server (Samba, Ubuntu)\n\n\n\ndns proxy = no\n\n\n\n\n\n\n\n
Editing the string before passing it to ConfigParser (replacing % with %%) parses it, but does the same issue as RawConfigParser where it parses the rest of the options as a single line.
How am I supposed to properly parse values that have a % in them?
Disable interpolation in the normal ConfigParser:
configparser.ConfigParser(interpolation=None)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With