urllib: geturl with max filesize?

Alex new_name at mit.edu
Tue Jun 26 09:18:11 EDT 2001


I don't know about other security issues.  It may depend on what you
plan to do with the content the user points you at.  But you can limit
the download size fairly easily:

import urllib
f = urllib.urlopen(url)

data = []
while len(data) < 1024:
    block = f.read(1024)
    if block == '': break
    data.append(block)

f.close()
write(''.join(data))

...will restrict the download to 1M, I guess.

HTH
Alex.



More information about the Python-list mailing list