Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MissingSectionHeaderError: File contains no section headers.(configparser)

I'm using configparser in order to read and modify automatically a file conf named 'streamer.conf'. I'm doing this :

import configparser

config = configparser.ConfigParser()
config.read('C:/Users/../Desktop/streamer.conf')

And then it breaks apart with this Error message :

MissingSectionHeaderError: File contains no section headers.
file: 'C:/Users/../Desktop/streamer.conf', line: 1
u'input{\n'

What might be wrong? Any help appreciated.

like image 265
Arij SEDIRI Avatar asked Nov 20 '25 09:11

Arij SEDIRI


2 Answers

just specify right encoding

config.read(config_file_path, encoding='utf-8-sig')
  • "utf-8-sig" for UTF-8 with BOM
  • "utf-8" for UTF-8 without BOM
like image 129
Vladimir Avatar answered Nov 22 '25 23:11

Vladimir


As mentioned in other answers the config file needs to be INI format, but the actual error you're seeing is due to the fact that the requested config file is missing any section headers (as mentioned in the error message) - these are names enclosed in square brackets which provide a header for a section of the INI file. The default header is [DEFAULT] e.g.

[DEFAULT]
 config_item1='something'
 config_item2=2
like image 36
Pierz Avatar answered Nov 22 '25 22:11

Pierz