Unzipping a .zip properly, and from a remote URL

Tino Wildenhain tino at wildenhain.de
Tue Feb 3 09:32:26 EST 2009


Christopher Culver wrote:
> Tino Wildenhain <tino at wildenhain.de> writes:
>> so instead you would use archive = zipfile.ZipFile(remotedata)
> 
> That produces the following error if I try that in the Python
> interpreter (URL edited for privacy):
> 
>>>> import zipfile
>>>> import urllib2
>>>> remotedata = urllib2.urlopen("http://...file.zip")
>>>> archive = zipfile.ZipFile(remotedata)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/lib/python2.5/zipfile.py", line 346, in __init__
>     self._GetContents()
>   File "/usr/lib/python2.5/zipfile.py", line 366, in _GetContents
>     self._RealGetContents()
>   File "/usr/lib/python2.5/zipfile.py", line 376, in _RealGetContents
>     endrec = _EndRecData(fp)
>   File "/usr/lib/python2.5/zipfile.py", line 133, in _EndRecData
>     fpin.seek(-22, 2)               # Assume no archive comment.
> AttributeError: addinfourl instance has no attribute 'seek'

Oh thats annoying. In this case short of providing a buffered
wrapper (which is possible) you would stick to the temp file
for an easy solution. Sorry about that.

Regards
Tino
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20090203/70e07037/attachment-0001.bin>


More information about the Python-list mailing list