RobD
RobD

Reputation: 455

How do I fix - 'File Containms no Section Headers error?

Trying to get some data out of an .ini file using this code, when I try to open the .ini it gives What Am I doing wrong?

config = configparser.ConfigParser()
config.sections()
config.read('FILE.ini') #throws file contains no section headers
print(config['DEFAULT']['toAddr'])
x = config.get('DEFAULT', 'to')

The .ini file

['DEFAULT']
to = "blah"

I'm using Python 3.7 64 on Win 10

Upvotes: 0

Views: 112

Answers (1)

Roland Smith
Roland Smith

Reputation: 43505

The header in the ini-file should not have quotes in it.

Use

[DEFAULT]
to = "blah"

instead of

['DEFAULT']
to = "blah"

Upvotes: 1

Related Questions