Python Glossary Русский

all Python 3Exceptionsexception

zlib.error

module exceptions

A zlib compression or decompression error (e.g. corrupted data).

Syntax

raise zlib.error

It derives straight from Exception, not from ValueError or OSError, so the usual except ValueError or except OSError won't catch it. The classic cause is feeding zlib.decompress the wrong format: gzip data has a different header (pass wbits=16+zlib.MAX_WBITS, or use the gzip module), and a truncated stream fails as incomplete instead of returning whatever decoded so far. When data arrives in chunks, decompress it through zlib.decompressobj.

Examples

import zlib
try:
    raise zlib.error
except zlib.error as e:
    print(type(e).__name__)   # → error

See also

Open in the full glossarydocs.python.orgReport an inaccuracy