今天使用ConfigParser解析一个ini文件,报出如下错误:

    config.read(logFile)File "C:\Python26\lib\ConfigParser.py", line 286, in readself._read(fp, filename)File "C:\Python26\lib\ConfigParser.py", line 482, in _readraise 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. centos 使用yum 安装出现 File contains no section headers 错误解决方法

    centos 使用yum 安装出现 File contains no section headers 错误解决方法 参考文章: (1)centos 使用yum 安装出现 File contains n ...

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

    [问题解决方案]CentOS7替换yum的问题:使用yum makecache出现File contains no section headers 参考文章: (1)[问题解决方案]CentOS7替换 ...

  3. F0011: error while parsing the configuration: File contains no section headers....

    关于F0011: error while parsing the configuration: File contains no section headers-问题解决-pylint 日志或者报告中 ...

  4. python库的学习系列之 13.2. ConfigParser — Configuration file parser

    13.2. ConfigParser - Configuration file parser 提供了一个ConfigParser.RawConfigParser方法,处理配置文件很好用,我们可以将配置 ...

  5. Win10 python双版本共存配置问题 Configuration file could not be loaded.

    根据博客配置双版本python共存,重装pip时遇到问题 Configuration file could not be loaded. File contains no section header ...

  6. ld: i386 architecture of input file `kernel.o‘ is incompatible with i386:x86-64 output

    学习操作系统时,链接几个用nasm汇编器生成的elf文件时,出现如题所示的错误提示. 操作如下: nasm -f elf kernel.asm -o kernel.o nasm -f elf stri ...

  7. [Android] 单独编译生成boot.img时mkbootfs: No such file or directory解决方法

    在一台没有安装Android源码编译环境的64位 Ubuntu14.04.5虚拟机上尝试单独编译Android用的Linux Kernel.并从编译好Android源码的机器上将out文件夹下的mkb ...

  8. 程序的本质之二ELF文件的文件头、section header和program header

    操作系统:CentOS Linux release 7.7.1908 内核版本:3.10.0-1062.1.1.el7.x86_64 运行平台:x86_64 参考文献:http://refspecs. ...

  9. ELF文件解析 ELF File Parsing

    ELF File Parsing ​ Executable and Linkable Format 实验材料:010editor readelf objdump linux_ls文件(x86-64) ...

最新文章

  1. redis学习笔记---redis的哨兵Sentinel
  2. citrix xenapp应用保存文件时隐藏服务器上的磁盘
  3. 线性代数:第四章 向量组的线性相关性(2)向量空间 线性方程组解的结构
  4. linux命令大写输入,在Linux命令行内的大小写转换
  5. (转载)谈谈JS里的{ }大括号和[ ]中括号的用法,理解后就可以看懂JSON结构了。...
  6. 【机器学习】主题模型
  7. python在城市规划中的运用_城市设计在城市规划管理中的运用
  8. 嵌入式Linux系统编程学习之二十六多线程概述
  9. sqlhelper 下载 使用指南 代码 [收藏]
  10. 【自】数据库系统原理(三)——测试总结后,
  11. 如何将 Mac 置入睡眠状态或唤醒 Mac?
  12. 关于Java Web工程中web.xml文件
  13. 如何建立开发环境可以让开发人员快捷开发出模型的原型
  14. 智能汽车软件关键技术及应用趋势
  15. 右键一直转圈圈(右键桌面和右键打开文件夹)的两种解决办法小总结
  16. python:实现newton_forward_interpolation牛顿前插算法(附完整源码)
  17. 骨传导耳机和普通耳机危害哪个小?骨传导耳机
  18. 还在到处寻找画图软件?快来用Typora画饼图、时序图、流程图、UML图和状态图吧
  19. 马宁伟-20年工作经验谈-4-男怕入错行
  20. 使用python解压缩rar、zip文件

热门文章

  1. 微观世界探索者:15家值得关注的纳米技术公司
  2. 斯坦福:「目标检测」深度学习全面指南
  3. 安谋中国发布“玲珑”i3i5 ISP处理器,剑指何方?
  4. springboot + shiro 验证码与记住登录
  5. 『高级篇』docker之APIGateway(17)
  6. java内外循环打印等腰三角*号
  7. 【NetApp】7mode options选项解释
  8. 07机器学习实战k-means
  9. javascript:正则表达式、一个表单验证的例子
  10. 大系统化小之后,微信如何解决大规模微服务下的难题?