1

I have a list of URIs of images from essentially a Wordpress site. I want to be able to have a script to get their file sizes (mb, kb, GB) from just using the URIs. I don't have access to this server-wise and need to add the sizes to a Google sheet. This seems like the fastest way to do it as there are over 5k images and attachments.

However when I do this in Python

>>> import requests
>>> response = requests.get("https://xxx.xxxxx.com/wp-content/uploads/2017/05/resources.png")
>>> len(response.content)
3232

I get 3232 bytes but when I check in Chrome Dev Tools, it's 3.4KB

enter image description here

What is being added? Or is the image actually 3.4KB and my script is only checking content-length? Also, I don't want to check using the Content-Length header as some of the images may be large and chunked so I want to be sure I'm getting the actual file size of the image.

What is a good way to go about this? I feel like there should be some minimal code or script I could run.

Kyle Calica-St
  • 2,629
  • 4
  • 26
  • 56

1 Answers1

1

The value you are seeing (3.4KB) includes the network overhead such as response headers.

As a side note, I am not sure what is the version of Chrome you are using but the transfer size (including response headers) and the resource size (i.e. the file size) are displayed separately for me:

Web Inspector

Selcuk
  • 57,004
  • 12
  • 102
  • 110
  • awesome! yup, I see it when I hover! thank you! Would you trust the `Content-Length` header to get the info I need? – Kyle Calica-St Nov 19 '19 at 06:22
  • 1
    Yes, the `Content-Length` header must be correct unless there is something configured horribly wrong on the server side. – Selcuk Nov 19 '19 at 22:58
  • even if the data gets "chunked" this `requests.get()` would get it after the "entire requests" completes for large images? – Kyle Calica-St Nov 20 '19 at 02:39
  • @KyleCalica-St: no, requests will not later on add a header; when using a chunked response you won’t be provided with a content-length. Also, the content-length can be *shorter* if the data was served with compression! See https://stackoverflow.com/a/50825553. – Martijn Pieters Jan 01 '20 at 23:55