今天使用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.的更多相关文章

  1. python ConfigParser读取配置文件,及解决报错(去掉BOM)ConfigParser.MissingSectionHeaderError: File contains no section headers的方法

    先说一下在读取配置文件时报错的问题--ConfigParser.MissingSectionHeaderError: File contains no section headers 问题描述: 在练 ...

  2. raise missingsectionheadererror:file containe no section headers问题解决

    本人亲测,遇到这个问题,就换到管理员方式运行命令 因为太小白,所以这次重新装包的时候切换到D盘了,想着省一点儿C盘内存,结果,每次pip install安装的时候都是这个问题,中间还有什么反序列失败, ...

  3. 【问题解决方案】CentOS7替换yum的问题:使用yum makecache出现File contains no section headers

    参考链接 CentOS7替换yum的问题:使用yum时出现File contains no section headers centos安装网络repo源及错误说明 一.centos替换yum的步骤 ...

  4. CentOS7使用yum时File contains no section headers.解决办法

    本文转载于  https://blog.csdn.net/trokey/article/details/84908838 安装好CenOS7后,自带的yum不能直接使用,使用会出现如下问题: 原因是没 ...

  5. ConfigParser读取记事本、notepad++修改后的配置文件会出现:ConfigParser.MissingSectionHeaderError

    使用ConfigParser来读取配置文件,经常会发现经过记事本.notepad++修改后的配置文件读取时出现下面的问题: ConfigParser.MissingSectionHeaderError ...

  6. ConfigParser读取配置文件时报错:ConfigParser.MissingSectionHeaderError

    使用ConfigParser来读取配置文件,经常会发现经过记事本.notepad++修改后的配置文件读取时出现下面的问题: ConfigParser.MissingSectionHeaderError ...

  7. Android7.0后JNI库必须保留Section Headers

    此修改在官网的描述如下: Each ELF file has additional information contained in the section headers. These header ...

  8. [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 ...

  9. mdk keil 指定变量、函数存储位置,使用 Scatter-Loading Description File, __attribute__(("section“))

    0. 数据类型说明 主要包括4类: Code (inc. data) ,属于RO,也就是写的函数代码(包括代码中的变量) RO Data , 属于RO,使用const修饰的变量. RW Data, 属 ...

随机推荐

  1. 32个触发事件XSS语句的总结

    1.onmouseenter:当鼠标进入选区执行代码 <div style="background-color:red" onmouseenter="alert(b ...

  2. bzoj 2875: [Noi2012]随机数生成器

    #include<cstdio> #include<iostream> #include<cstring> #define ll long long using n ...

  3. jsoup 简介

    Java 程序在解析 HTML 文档时,相信大家都接触过 htmlparser 这个开源项目,我曾经在 IBM DW 上发表过两篇关于 htmlparser 的文章,分别是:从HTML中攫取你所需的信 ...

  4. JavaScript本地对象 内置对象 宿主对象

          在ECMAScript中,所有对象并非同等创建的. 一般来说,可以创建并使用的对象有3种:本地对象.内置对象和宿主对象. 1. 本地对象 ECMA-262把本地对象(native obje ...

  5. MSSQL常用函数

    declare 定义变量 set 为变量赋值 SUBSTRING()函数 SUBSTRING ( expression, start, length ) expression 字符串.二进制字符串.文 ...

  6. ANT build.xml文件详解

    Ant的优点 跨平台性.Ant是用Java语言编写的,所示具有很好的跨平台性. 操作简单.Ant是由一个内置任务和可选任务组成的. Ant运行时需要一个XML文件(构建文件). Ant通过调用targ ...

  7. Pig与Hive的区别

    Language 在Hive中可以执行  插入/删除 等操作,但是Pig中我没有发现有可以 插入 数据的方法,请允许我暂且认为这是最大的不同点吧. Schemas Hive中至少还有一个“表”的概念, ...

  8. transform:rotate在手机上显示有锯齿的解决方案

    transform:rotate 属于简单好用的效果,但在手机上显示时,会有比较明显锯齿. 解决方案也很简单, 利用外层容器的overflow:hidden 加上图片margin:-1px 就可以解决 ...

  9. 2014年3月份第3周51Aspx源码发布详情

    WPF翻书效果源码  2014-3-17 [VS2010]源码描述:WPF翻书效果源码:多点触控的一个Demo,利用鼠标可以实现图书翻页效果:适合新手学习研究. TL简单家具网新手源码  2014-3 ...

  10. PHP中的null合并运算符

    project: blog target: null-coalesce-operator-in-php.md date: 2015-12-30 status: publish tags: - Null ...