I'm trying to create tables in my database (postgresql 9.6) and when I launch my python script to do so, it returns me an error of the following type:
"Section postgresql not found in the $FILEDIR/database.ini file"
It seems like the parser cannot read the section, but I don't understand why.
This is my config method:
def config(filename='$FILEDIR/database.ini', section='postgresql'):
parser = ConfigParser()
parser.read(filename)
db = {}
if parser.has_section(section):
params = parser.items(section)
for param in params:
db[param[0]] = param[1]
else:
raise Exception('Section {0} not found in the {1} file'.format(section, filename))
return db
Database.ini:
[postgresql]
host=localhost
database=mydatabase
user=myuser
password=mypassword
I've tried the answers in this following thread but it does not help me at all. Anyone knows the cause? I'm using python 2.7 and I've executed "pip install config" and "pip install configparser" for dependencies.