Size of a remote URL
Dave Brueck
dave at pythonapocrypha.com
Mon Aug 30 14:14:40 EDT 2004
Justin wrote:
> Ok. I believe you are correct. I have observed the two MODES of the
> download dialog box. HOWEVER there are still some instances in which
> Internet Explorer knows the size of something that my code cannot
> determine. So now I have this conclusion: The instances where I
> cannot get the size but a browser can must exist because I am not
> asking the server the right question.
Post a URL and I'll give it a try for you.
> Perhaps "Content-Length" is not
> included in the default headers, but the server will provide this
> header if it is asked too?
It's _possible_ that whether or not the content-length header is returned is
affected by e.g. the protocol you say you're using (HTTP 1.0 vs 1.1, for
example), but that wouldn't be my first guess.
> Maybe I need to ask for that header more
> specifically?
No, there's not really any way to do that in HTTP.
> Also do you know of a simpler method than urlopen?
Sure, you can always use plain old sockets:
from socket import *
s = socket(AF_INET, SOCK_STREAM)
s.connect(('www.google.com', 80))
s.send('HEAD / HTTP/1.0\r\n\r\n')
while 1:
more = s.recv(4096)
if not more: break
print more
-Dave
More information about the Python-list
mailing list