MissingSectionHeaderError:文件不包含节标题。(configparser) [英] MissingSectionHeaderError: File contains no section headers.(configparser)

查看:133
本文介绍了MissingSectionHeaderError:文件不包含节标题。(configparser)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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'

怎么了?

推荐答案

只需指定正确的编码

config.read(config_file_path, encoding='utf-8-sig')




  • 带有BOM的UTF-8的 utf-8-sig

  • 没有BOM的UTF-8的 utf-8-sig

  • 这篇关于MissingSectionHeaderError:文件不包含节标题。(configparser)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆