I am using python with requests module to fetch data from api with a json feed. When I include the request for gzip as the encoding I am not seeing any change. Am I implementing it the wrong way here?
my_headers = {'accept-encoding':'gzip'}
response = requests.get(url, headers=my_headers)
print(response.headers)
print(len(response.content))
The response headers always come back with
'Content-Encoding': 'gzip'
but this happens with or without the inclusion of my request headers, the length and load times do not change either
To compress an existing file to a gzip archive, read text in it and convert it to a bytearray. This bytearray object is then written to a gzip file. In the example below, 'zen. txt' file is assumed to be present in current directory.
File format gzip is based on the DEFLATE algorithm, which is a combination of LZ77 and Huffman coding. DEFLATE was intended as a replacement for LZW and other patent-encumbered data compression algorithms which, at the time, limited the usability of compress and other popular archivers.
Requests: HTTP for Humans - Binary Response Content
gzip and deflate transfer-encodings are automatically decoded for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With