Search code examples
pythongzipzlib

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


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 this error:

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

How can I overcome it?


Solution

  • Update: dnozay's answer explains the problem and should be the accepted answer.


    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()