I've been trying to find the default behavior of the requests module about the compression, but I couldn't find anything, so I'm asking here:
Does the requests module asks the server for compression by default, or not ? Do we have to specify it in the header ?
I found a page here talking about urllib, where it is said that the header must ask for compression to get it:
http://www.diveintopython.net/http_web_services/gzip_compression.html
Is it the same thing for requests ?
You can test it yourself. Try the following:
import requests
req = requests.get("http://google.com")
print(req.request.headers)
This will print the headers sent to the server (the default ones, since no other headers are defined). On my system I get:
{'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.7.0 CPython/2.7.8 Linux/4.1.8-100.fc21.x86_64'}
So, gzip
and deflate
are accepted compression types. The server will choose one of those.
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