I am getting the following error--- "configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%dCUD'"
I want to read credentials which are set as an environment variables as well as present in .config file. So I am using pythons ConfigParser as follows.
import configparser as cp
from configparser import ConfigParser
config = ConfigParser(os.environ) #<-- this enables ConfigParser to read from environment variable
config.read(CONFIG_FILEPATH) #<--- this is to read from .confog file
My .config file is like this--
[Postgres]
Postgres.host = XXX.com
Postgres.METADATADB=pda-study-beta
Postgres.DATAREFRESHDB=
Postgres.user= %(XXXX)s
Postgres.password = %(Postgres_Pass)s
anything included inside *%()s* means it is being read from environment variable.
I read it in my scripts as follows:
config.get('Postgres','Postgres.password')
It works fine for all but for password, its throwing me following error in password section--
"configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%dCUD'"
Its because my password contains '%' character. e.g.(xxx%dCUDxx)
Does any one have any idea how do I handle this. We can escape % with another %, but in my case, I am reading password from environment variable, so cant manipulate it.
Can anyone please help me resolve this ?