Zipfile module errors

John Machin sjmachin at lexicon.net
Wed Jun 4 13:45:15 CEST 2008


On Jun 4, 8:06 pm, jwesonga <crazylun... at gmail.com> wrote:
> Hi,
>
> I have a python script that supposed to go through a folder, pick the
> zipped files, unzip them and process the data inside. I'm not sure
> where i'm going wrong with this script because it all seems correct:

Nothing is ever as it seems. Let's try to work backwards from the
error message ... and we don't need your magnificent script, just the
traceback will do for now, so:

[ big snip]

>
> The error I keep getting is:
>
> Traceback (most recent call last):
>   File "processor3.py", line 124, in ?
>     unzip(infolder)
>   File "processor3.py", line 53, in unzip

The error says that you are trying to seek 22 bytes backwards from the
end of a file that you presume is a zip file, and this is deemed to be
invalid. Hypotheses: (1) zipfile.py is buggy (2) your file is less
than 22 bytes long. Let's park hypothesis 1 for the moment. Insert the
following code before the call to zipfile.ZipFile:

print "trying to unzip %r whose size is %d bytes" \
    % (one, os.stat(one).st_size)

and tell us your conclusions.

>     zfile = zipfile.ZipFile(one,'r')
>   File "/usr/lib/python2.4/zipfile.py", line 210, in __init__
>     self._GetContents()
>   File "/usr/lib/python2.4/zipfile.py", line 230, in _GetContents
>     self._RealGetContents()
>   File "/usr/lib/python2.4/zipfile.py", line 240, in _RealGetContents
>     endrec = _EndRecData(fp)
>   File "/usr/lib/python2.4/zipfile.py", line 83, in _EndRecData
>     fpin.seek(-22, 2)               # Assume no archive comment.
> IOError: [Errno 22] Invalid argument

P.S. Printing the contents of filelist immediately after it's been
created might be a good idea. You say "pick the zipped files" but the
only condition I see is a test using os.path.isdir.

HTH,
John



More information about the Python-list mailing list