Search code examples
urlpython-requestsgzip

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


Solution

  • Requests: HTTP for Humans - Binary Response Content

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