How do I 'stat' online files?

Gabriel Genellina gagsl-py2 at
Thu Jul 26 03:05:15 CEST 2007

En Wed, 25 Jul 2007 15:11:19 -0300, Carsten Haese <carsten at>  

> On Tue, 2007-07-24 at 22:23 -0300, Gabriel Genellina wrote:
>> En Tue, 24 Jul 2007 10:47:16 -0300, Carsten Haese <carsten at>
>> escribió:
>> > On Tue, 2007-07-24 at 09:07 -0400, DB Daniel Brown wrote:
>> >> I am working on a program that needs to stat files (gif, swf, xml,
>> >> dirs, etc) from the web. I know how to stat a local file…
>> >
>> > That's because urlopen returns a file-like object, not a file. The  
>> best
>> > you can hope for is to inspect the headers that the web server  
>> returns:
>> >
>> >>>> f = urllib.urlopen("")
>> This generates an HTTP GET request - transfering the contents too,
>> innecesarily.
> Yes, but how much of that content will actually be transferred if I
> don't call

Transferred? The server perhaps has sent all of it, depending on its  
configuration and available bandwidth. The first packets will be in your  
TCP receiving buffers even if you never call So be nice to the  
origin server, the whole Internet, and our planet, and don't waste  
bandwidth and energy in requesting things that you're going to throw away  

> I doubt that my computer just downloaded 4 MB of stuff in 0.3 seconds.

Probably not, but I'd use netstat or ntop to find out how much has  
actually been downloaded.

Gabriel Genellina

More information about the Python-list mailing list