Python zipfile报错问题
来源:互联网 发布:文本编辑 mac 编辑:程序博客网 时间:2024/05/01 07:33
最近用Python 来读zip的压缩包 。报一个错误。
Python 2.6.6 (r266:84292, Jun 18 2012, 14:18:47) [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import zipfile>>> zipfile.ZipFile('bla.apk')Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.6/zipfile.py", line 696, in __init__ self._GetContents() File "/usr/lib64/python2.6/zipfile.py", line 716, in _GetContents self._RealGetContents() File "/usr/lib64/python2.6/zipfile.py", line 772, in _RealGetContents x._decodeExtra() File "/usr/lib64/python2.6/zipfile.py", line 351, in _decodeExtra tp, ln = unpack('<HH', extra[:4])struct.error: unpack requires a string argument of length 4
这应该算是 Python的一个bug ,详细的在 http://bugs.python.org/issue14315 这里有讨论。
解决方法有两个。
一是 : 按照这个网页所讨论的, 打一个补丁 。http://bugs.python.org/file24902/fix_zipfile_extra.patch 。
具体就是 进入 /usr/lib64/python2.6/zipfile.py 这个文件 ,在 351行附近 ,把 while extra: 改成 while len(extra) >= 4:
方法二是 升级 Python版本 。
在Python 2.6.6 上发现了这个问题 。这个Python是Linux自带的版本,可能比较低。升级2.7.3 以上的版本 ,在高版本中这个问题已经被解决了。 所以升级Python也是个办法。
0 0
- Python zipfile报错问题
- Python-zipfile解压中文问题
- python zipfile
- Python zipfile
- Python zipfile
- python zipfile
- python模块之zipfile
- python--zipfile
- python模块之zipfile
- python zipfile模块
- python中的zipfile
- python zipfile压缩工具
- python zipfile模块测试
- python小模块---zipfile
- python 的 zipfile 模块
- 关于Python中的zipfile
- 【Python】压缩文件 zipfile
- python zipfile小例子
- TL和DL结合论文整理(不断更新中)
- IAR 使用说明
- UVa 1368 - DNA Consensus String
- C#之伪静态实现
- 装饰模式(DecoratorPattern)与继承(Extends)的区别
- Python zipfile报错问题
- declare-styleable自定义控件属性
- Mutant Flatworld Explorers
- 一个程序员的多年珍藏
- python 坑:list的扩展
- Android Fragment完全解析
- Silverlight读取XML
- 超链接a标签另一个常被使用的功能:锚点(name和#)
- POJ 3261 Milk Patterns 后缀数组