[docs] urllib2.urlopen()

Ole Streicher debian at liska.ath.cx
Mon Mar 11 17:43:18 CET 2013


I just tried to directly open a tar file from an URL:

import urllib2
import tarfile

url = "http://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz"
tar = tarfile.open(fileobj = urllib2.urlopen(url))

This doesn't work since urllib2.urlopen() does not return a seekable
file, but tarfile.open() expects one.

This limitation is not mentioned in the documentation of urlopen(),
instead is misleadingly states:

"This function returns a file-like object with two additional methods:

I would suggest to add here that the returned object is not seekable, or
a "Socket-like" object or similar.

Oh, and the object has *three* additional methods, not two (geturl(),
info(), getcode()).

Please include me in an replay as I am not subscribed to the list.

Best regards


More information about the docs mailing list