ConfigParser.MissingSectionHeaderError: File contains no section headers.
今天使用ConfigParser解析一个ini文件,报出如下错误:

config.read(logFile)
File "C:\Python26\lib\ConfigParser.py", line 286, in read
self._read(fp, filename)
File "C:\Python26\lib\ConfigParser.py", line 482, in _read
raise MissingSectionHeaderError(fpname, lineno, line)
MissingSectionHeaderError: File contains no section headers.
file: C:\test\test.ini, line: 1
'\xff\xfe\r\x00\n'

经过分析是由于文件编码方式导致,调整代码如下,问题解决:
def test():
logFile = r'C:\test\test.ini'
config = ConfigParser.ConfigParser()
config.readfp(codecs.open(logFile, "r", "utf_16"))
print config.sections()
此文件为unicode编码,所以这里填入"utf_16",如果为其他编码格式,则修改该参数。
python编码查询地址:http://docs.python.org/2/library/codecs.html?highlight=streamcodec#standard-encodings
ConfigParser.MissingSectionHeaderError: File contains no section headers.的更多相关文章
- python ConfigParser读取配置文件,及解决报错(去掉BOM)ConfigParser.MissingSectionHeaderError: File contains no section headers的方法
先说一下在读取配置文件时报错的问题--ConfigParser.MissingSectionHeaderError: File contains no section headers 问题描述: 在练 ...
- raise missingsectionheadererror:file containe no section headers问题解决
本人亲测,遇到这个问题,就换到管理员方式运行命令 因为太小白,所以这次重新装包的时候切换到D盘了,想着省一点儿C盘内存,结果,每次pip install安装的时候都是这个问题,中间还有什么反序列失败, ...
- 【问题解决方案】CentOS7替换yum的问题:使用yum makecache出现File contains no section headers
参考链接 CentOS7替换yum的问题:使用yum时出现File contains no section headers centos安装网络repo源及错误说明 一.centos替换yum的步骤 ...
- CentOS7使用yum时File contains no section headers.解决办法
本文转载于 https://blog.csdn.net/trokey/article/details/84908838 安装好CenOS7后,自带的yum不能直接使用,使用会出现如下问题: 原因是没 ...
- ConfigParser读取记事本、notepad++修改后的配置文件会出现:ConfigParser.MissingSectionHeaderError
使用ConfigParser来读取配置文件,经常会发现经过记事本.notepad++修改后的配置文件读取时出现下面的问题: ConfigParser.MissingSectionHeaderError ...
- ConfigParser读取配置文件时报错:ConfigParser.MissingSectionHeaderError
使用ConfigParser来读取配置文件,经常会发现经过记事本.notepad++修改后的配置文件读取时出现下面的问题: ConfigParser.MissingSectionHeaderError ...
- Android7.0后JNI库必须保留Section Headers
此修改在官网的描述如下: Each ELF file has additional information contained in the section headers. These header ...
- [CSS3] Use Sticky Positioning for Section Headers
We can take advantage of sticky positioning to keep a section header at the top of the page while th ...
- mdk keil 指定变量、函数存储位置,使用 Scatter-Loading Description File, __attribute__(("section“))
0. 数据类型说明 主要包括4类: Code (inc. data) ,属于RO,也就是写的函数代码(包括代码中的变量) RO Data , 属于RO,使用const修饰的变量. RW Data, 属 ...
随机推荐
- String课后作业
请查看String.equals()方法的实现代码,注意学习其实现方法. public class StringEquals { @param args the command line argume ...
- asp.net还原备份数据库(C#)
因为做项目的时候用到对数据库的还原和备份,第一次接触,所以上网查了关于这方面的资料,网络果然是个好东西,该有的都有了,这里我就把原文中的代码直接粘贴过来了. using System; using S ...
- 在 Apache error_log 中看到多个信息,提示 RSA server certificate CommonName (CN) 与服务器名不匹配(转)
在 Apache error_log 中看到多个信息,提示 RSA server certificate CommonName (CN) 与服务器名不匹配. Article ID: 1500, cre ...
- 启动本地Oracle
net start OracleOraDb10g_home1TNSListenernet start OracleServiceORCL第一个是监听服务第二个是数据库服务
- 2016年发布APASVO-p波震相自动拾取分析
Why automatic attractive? large amount of seismic data ; if manually,it depends om experience of ana ...
- 编程技术●Python
<Python语言入门> 2015-01-16 14:13 ★ 虽然书名叫入门.序里也写了说完全没有编程经验的都可以用这本书来学习入门.不过好像不太适合哦.书很好,内容也挺全面细致的.太好 ...
- C#获取字符首字母
///<summary> /// 获取字符首字母 /// </summary> public static string GetPyChar(string c) { if (s ...
- python3登录极路由并读取宽带帐号帐号密码.py
python3登录极路由并读取宽带帐号帐号密码,fiddler抓包分析过程略... 步骤:1.登录路由,提取stok. 2.用stok拼成url,post请求 3.解析json数据 代码: " ...
- javaweb-dbutils2
package cn.itcast.demo; import java.sql.SQLException;import java.util.Arrays;import java.util.List;i ...
- 黑马程序员——【Java高新技术】——反射机制
---------- android培训.java培训.期待与您交流! ---------- 一.概述 1.Java反射机制:是指“在运行状态中”,对于任意一个类,都能够知道这个类中的所有属性和方法: ...