MissingSectionHeaderError: File contains no section headers.(configparser)

Arij SEDIRI picture Arij SEDIRI · Oct 3, 2016 · Viewed 19.3k times · Source

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.

Answer

Vladimir picture Vladimir · Oct 4, 2017

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