Get file size using python-requests, while only getting the header

Send a HEAD request:

>>> import requests
>>> response = requests.head('http://example.com')
>>> response.headers
    {'connection': 'close',
 'content-encoding': 'gzip',
 'content-length': '606',
 'content-type': 'text/html; charset=UTF-8',
 'date': 'Fri, 11 Jan 2013 02:32:34 GMT',
 'last-modified': 'Fri, 04 Jan 2013 01:17:22 GMT',
 'server': 'Apache/2.2.3 (CentOS)',
 'vary': 'Accept-Encoding'}

A HEAD request is like a GET request that only downloads the headers. Note that it’s up to the server to actually honor your HEAD request. Some servers will only respond to GET requests, so you’ll have to send a GET request and just close the connection instead of downloading the body. Other times, the server just never specifies the total size of the file.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)