MissingSectionHeaderError:文件不包含节标题。(configparser)

Dat*_*ted 3 python configuration configuration-files configparser python-2.7

我正在使用 configparser 来自动读取和修改名为“streamer.conf”的文件 conf。我正在这样做:

import configparser

config = configparser.ConfigParser()
config.read('C:/Users/../Desktop/streamer.conf')
Run Code Online (Sandbox Code Playgroud)

然后它与此错误消息分开:

MissingSectionHeaderError: File contains no section headers.
file: 'C:/Users/../Desktop/streamer.conf', line: 1
u'input{\n'
Run Code Online (Sandbox Code Playgroud)

可能有什么问题?任何帮助表示赞赏。

Vla*_*mir 5

只需指定正确的编码

config.read(config_file_path, encoding='utf-8-sig')
Run Code Online (Sandbox Code Playgroud)
  • 带有 BOM 的 UTF-8 的“utf-8-sig”
  • “utf-8”表示没有 BOM 的 UTF-8