1 year ago

#141374

test-img

facialrecognition

How to get file size if content-length does not exist?

I have a file I'd like Python to find out and print its file size. Unfortunately, the headers do not have the key content-length. Is there a workaround to finding the file size without content-length? Thanks.

import requests

link = "https://web.archive.org/cdx/search/cdx?url=twitter.com/realdonaldtrump/status&matchType=prefix&filter=statuscode:200"

response = requests.head(link)
print(response.headers['content-length'])

Error:

    return self._store[key.lower()][1]
KeyError: 'content-length'

python

python-requests

filesize

content-length

0 Answers

Your Answer

Accepted video resources