Recipes

This page includes a collection of recipes in the urlib3 cookbook.

Decode HTTP Response Data in Concatenated Gzip Format

By default, urllib3 checks Content-Encoding header in HTTP response and decodes the data in gzip or deflate transparently. If Content-Encoding is not either of them, however, you will have to decode data in your application.

This recipe shows how to decode data in the concatenated gzip format where multiple gzipped data chunks are concatenated in HTTP response.

obj.unused_data includes the left over data in the previous obj.decompress method call. A new zlib.decompressobj is used to start decoding the next gzipped data chunk until no further data is given.