No Content-Length header, nor length property

Kev Dwyer kevin.p.dwyer at
Wed Jul 8 07:28:07 CEST 2015

zljubisic at wrote:

> Hi,
> if I put the link in the browser, I will be offered to save the file to
> the local disk.
> If I execute these few lines of code, I will get None:
> import urllib.request
> url = ''
> site = urllib.request.urlopen(url)
> print('File size:', site.length)
> Why I can't get the size of this particular file?
> On other servers, the same procedure would return file size in bytes, but
> not for this file?
> Does it depend on server itself, or there is a way to get remote file size
> before downloading?
> Regards.


urlopen returns an HttpResponse 
object(  You need to call read() on the return value to get the page 
content, or you could consider the getheader method to check for a Content-
Length header.

Hope that helps,


More information about the Python-list mailing list