tags:

views:

162

answers:

1

Hi, I have a gzip file and I am trying to read it via python as below:

import zlib

do = zlib.decompressobj(16+zlib.MAX_WBITS) fh = open('abc.gz', 'rb') cdata = fh.read() fh.close() data = do.decompress(cdata)

it throws : zlib.error: Error -3 while decompressing: incorrect header check

How can I overcome it.

A: 

Try the gzip module, code below is straight from the python docs.

import gzip
f = gzip.open('/home/joe/file.txt.gz', 'rb')
file_content = f.read()
f.close()
Dave Bacher
Same error presented :Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/gzip.py", line 212, in read self._read(readsize) File "/usr/lib/python2.6/gzip.py", line 271, in _read uncompress = self.decompress.decompress(buf)zlib.error: Error -3 while decompressing: invalid code lengths set
VarunVyas
@VarunVyas, sorry, I can't reproduce your error. It must have something to do with your input data. Was your input file generated with gzip? Does gunzip from the command line decompress it correctly?
Dave Bacher