python - MissingSectionHeaderError : File contains no section headers. (configparser)

标签 python python-2.7 configuration configuration-files configparser

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

import configparser

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

然后它分解并显示此错误消息:

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

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

最佳答案

只需指定正确的编码

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

关于python - MissingSectionHeaderError : File contains no section headers. (configparser),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39831956/

相关文章:

python - 如何在matplotlib中设置刻度之间的固定间距

python - 如何在给定整数索引的情况下检索 pandas 数据帧行的标签索引?

java - 消除不必要的 log4j 设置输出

WCF 未在 IIS 6.0 下运行

java - 获取 Eclipse 运行时配置键和值

python - 如何从文件夹加载变压器管道?

python - 如何使用 Python Requests 模块登录 Google?

python - 有没有一种方法可以在不运行 Python 脚本的情况下自动验证所有导入?

python - 如何从多对多关系中检索条目

python - matplotlib barplot 不适用于对数刻度