Section postgresql not found in the database.ini file

0 votes

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.

Oct 3, 2018 in Python by eatcodesleeprepeat
• 4,670 points
125 views

1 answer to this question.

0 votes

Python doesn't know what $FILEDIR is. Try an absolute path to the .ini file.

answered Oct 3, 2018 by Priyaj
• 56,520 points

Related Questions In Python

0 votes
1 answer

How to print a message or the error if a file is not found?

To print the message that file is not ...READ MORE

answered Jan 2 in Python by Omkar
• 67,290 points
25 views
+1 vote
5 answers

Check whether the file exists or not?

Use this import os os.path.exists(path) # Returns whether the ...READ MORE

answered Oct 18, 2018 in Python by reyam
79 views
0 votes
1 answer
0 votes
1 answer

nmap.nmap.PortScannerError: 'nmap program was not found in path

python-nmap module used in python happens to use nmap binary ...READ MORE

answered Jan 30 in Python by Omkar
• 67,290 points
842 views
0 votes
1 answer

Iterating over dictionaries using 'for' loops

key is just a variable name. for key ...READ MORE

answered Oct 8, 2018 in Python by SDeb
• 13,160 points
48 views
0 votes
1 answer

Conflicting dependencies of pypyodbc and blpapi

I figured out that pypyodbc only works ...READ MORE

answered Oct 9, 2018 in Python by Priyaj
• 56,520 points
80 views
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,720 points
1,518 views
0 votes
1 answer

What is the flow control for “continue” in python?

This is the way "continue" statement works! You ...READ MORE

answered Jul 16, 2018 in Python by Priyaj
• 56,520 points
48 views