[New-bugs-announce] [issue11211] gzip.open() fails for gzipped file

Toni Mueller report at bugs.python.org
Mon Feb 14 16:08:19 CET 2011

New submission from Toni Mueller <tonimueller at users.sourceforge.net>:

I have files that I would like to read with Python, but can't:

$ python jmlreader.py woerter-allg.jml
Traceback (most recent call last):
  File "jmlreader.py", line 14, in <module>
  File "jmlreader.py", line 10, in readFile
    for line in f:
  File "/usr/lib/python2.6/gzip.py", line 438, in next
    line = self.readline()
  File "/usr/lib/python2.6/gzip.py", line 393, in readline
    c = self.read(readsize)
  File "/usr/lib/python2.6/gzip.py", line 219, in read
  File "/usr/lib/python2.6/gzip.py", line 255, in _read
  File "/usr/lib/python2.6/gzip.py", line 156, in _read_gzip_header
    raise IOError, 'Not a gzipped file'
IOError: Not a gzipped file

The file itself is a gzipped file, though: 

$ gzip -cd woerter-allg.jml|head
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Category name="All">
<Card AmountLearnedBack="0" AmountLearnedFront="0" Backside="yu3 yan2  (zhong3)&#10;&#10;Sprache" DateCreated="02-Mar-2009 16:05:15" DateModified="02-Mar-2009 16:05:15" DateTouched="02-Mar-2009 16:05:15" Frontside="语言(种)" TestsHit="0" TestsTotal="0">
<Card AmountLearnedBack="0" AmountLearnedFront="0" Backside="shu4&#10;&#10;Baum, pflanzen, hervorbringen" DateCreated="02-Mar-2009 16:06:26" DateModified="02-Mar-2009 16:06:49" DateTouched="02-Mar-2009 16:06:26" Frontside=" 树" TestsHit="0" TestsTotal="0">

Unfortunately, the file is a bit weird:

$ file woerter-allg.jml
woerter-allg.jml: Zip archive data, at least v2.0 to extract

Rewriting the program with zlib, instead of gzip, didn't help a bit:

$ python jmlreader.py woerter-allg.jml.gz 
Traceback (most recent call last):
  File "jmlreader.py", line 15, in <module>
  File "jmlreader.py", line 11, in readFile
    unc = zlib.decompress(s)
zlib.error: Error -3 while decompressing data: incorrect header check

IOW, the file was actually compressed with gzip, not zip.

It would be nice if the gzip module could read the file. I've attached a file that reproduces the problem.

components: Extension Modules
files: test.jml
messages: 128550
nosy: tonimueller
priority: normal
severity: normal
status: open
title: gzip.open() fails for gzipped file
type: behavior
versions: Python 2.6
Added file: http://bugs.python.org/file20760/test.jml

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list