Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gzip url request in python

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

like image 595
ms18 Avatar asked Jun 16 '18 09:06

ms18


People also ask

How do I gzip in Python?

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.

What encoding does gzip use?

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.


1 Answers

Requests: HTTP for Humans - Binary Response Content

gzip and deflate transfer-encodings are automatically decoded for you.

like image 194
ms18 Avatar answered Oct 15 '22 23:10

ms18