Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make GET request with python-requests without downloading content

If I make

r = requests.get('http://github.com', stream=True)

and see in tcpdump, the content of page downloaded just after requests.get. After r.content, no tcpdump transfer activity. The same with requests.Session(stream=True).

like image 390
fakel Avatar asked Mar 09 '26 11:03

fakel


1 Answers

Don't use GET if you don't want a response body to be sent by the server. Use a HEAD request instead if all you need is the header information.

All stream=True does is not read the response body from the socket. The server can still initiate sending that body, so the socket receive buffer will already have (some) of that body for Python to read.

like image 173
Martijn Pieters Avatar answered Mar 11 '26 06:03

Martijn Pieters