ConfigParser MissingSectionHeaderError: File contains no section headers.
今天使用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.相关推荐
- centos 使用yum 安装出现 File contains no section headers 错误解决方法
centos 使用yum 安装出现 File contains no section headers 错误解决方法 参考文章: (1)centos 使用yum 安装出现 File contains n ...
- 【问题解决方案】CentOS7替换yum的问题:使用yum makecache出现File contains no section headers
[问题解决方案]CentOS7替换yum的问题:使用yum makecache出现File contains no section headers 参考文章: (1)[问题解决方案]CentOS7替换 ...
- F0011: error while parsing the configuration: File contains no section headers....
关于F0011: error while parsing the configuration: File contains no section headers-问题解决-pylint 日志或者报告中 ...
- python库的学习系列之 13.2. ConfigParser — Configuration file parser
13.2. ConfigParser - Configuration file parser 提供了一个ConfigParser.RawConfigParser方法,处理配置文件很好用,我们可以将配置 ...
- Win10 python双版本共存配置问题 Configuration file could not be loaded.
根据博客配置双版本python共存,重装pip时遇到问题 Configuration file could not be loaded. File contains no section header ...
- 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 ...
- [Android] 单独编译生成boot.img时mkbootfs: No such file or directory解决方法
在一台没有安装Android源码编译环境的64位 Ubuntu14.04.5虚拟机上尝试单独编译Android用的Linux Kernel.并从编译好Android源码的机器上将out文件夹下的mkb ...
- 程序的本质之二ELF文件的文件头、section header和program header
操作系统:CentOS Linux release 7.7.1908 内核版本:3.10.0-1062.1.1.el7.x86_64 运行平台:x86_64 参考文献:http://refspecs. ...
- ELF文件解析 ELF File Parsing
ELF File Parsing Executable and Linkable Format 实验材料:010editor readelf objdump linux_ls文件(x86-64) ...
最新文章
- redis学习笔记---redis的哨兵Sentinel
- citrix xenapp应用保存文件时隐藏服务器上的磁盘
- 线性代数:第四章 向量组的线性相关性(2)向量空间 线性方程组解的结构
- linux命令大写输入,在Linux命令行内的大小写转换
- (转载)谈谈JS里的{ }大括号和[ ]中括号的用法,理解后就可以看懂JSON结构了。...
- 【机器学习】主题模型
- python在城市规划中的运用_城市设计在城市规划管理中的运用
- 嵌入式Linux系统编程学习之二十六多线程概述
- sqlhelper 下载 使用指南 代码 [收藏]
- 【自】数据库系统原理(三)——测试总结后,
- 如何将 Mac 置入睡眠状态或唤醒 Mac?
- 关于Java Web工程中web.xml文件
- 如何建立开发环境可以让开发人员快捷开发出模型的原型
- 智能汽车软件关键技术及应用趋势
- 右键一直转圈圈(右键桌面和右键打开文件夹)的两种解决办法小总结
- python:实现newton_forward_interpolation牛顿前插算法(附完整源码)
- 骨传导耳机和普通耳机危害哪个小?骨传导耳机
- 还在到处寻找画图软件?快来用Typora画饼图、时序图、流程图、UML图和状态图吧
- 马宁伟-20年工作经验谈-4-男怕入错行
- 使用python解压缩rar、zip文件