unzip problem

Ahmed, Shakir shahmed at sfwmd.gov
Fri Jun 24 13:31:51 EDT 2011



-----Original Message-----
From: python-list-bounces+shahmed=sfwmd.gov at python.org
[mailto:python-list-bounces+shahmed=sfwmd.gov at python.org] On Behalf Of
Philip Semanchuk
Sent: Friday, June 24, 2011 11:18 AM
To: Lista-Comp-Lang-Python list
Subject: Re: unzip problem


On Jun 24, 2011, at 10:55 AM, Ahmed, Shakir wrote:

> Hi,
> 
> 
> 
> I am getting following error message while unziping a .zip file. Any
> help or idea is highly appreciated.
> 
> 
> 
> Error message>>>
> 
> Traceback (most recent call last):
> 
>  File "C:\Zip_Process\py\test2_new.py", line 15, in <module>
> 
>    outfile.write(z.read(name))
> 
> IOError: (22, 'Invalid argument')


Start debugging with these two steps --
1) Add this just after "for name in z.namelist():"
   print name

That way you can tell which file is failing.

2) You can't tell whether you're getting an error on the write or the
read because you've got two statements combined into one line. Change
this --
   outfile.write(z.read(name))
to this --
   data = z.read(name)
   outfile.write(data)


Good luck
Philip

> 
> 
> 
> 
> 
> The script is here:
> 
> *****************************
> 
> fh = open('T:\\test\\*.zip', 'rb')
> 
> z = zipfile.ZipFile(fh)
> 
> for name in z.namelist():
> 
>    outfile = open(name, 'wb')
> 
> 
> 
>    outfile.write(z.read(name))
> 
>    print z
> 
>    print outfile
> 
>    outfile.close()
> 
> 
> 
> fh.close()
> 
> ********************************


The problem found in outfile.Write. The error code is here and is
happening when few of the files are already unzipped from the zip file

>>> T:\applications\tst\py\Zip_Process
>>> drg100.aux
>>> <zipfile.ZipFile instance at 0x00E2F648>
>>> <open file 'drg100.aux', mode 'wb' at 0x00E12608>
>>> drg100.fgdc.htm
>>> <zipfile.ZipFile instance at 0x00E2F648>
>>> <open file 'drg100.fgdc.htm', mode 'wb' at 0x00E128D8>
>>> drg100.htm
>>> <zipfile.ZipFile instance at 0x00E2F648>
>>> <open file 'drg100.htm', mode 'wb' at 0x00E12608>
>>> drg100.sdw
>>> <zipfile.ZipFile instance at 0x00E2F648>
>>> <open file 'drg100.sdw', mode 'wb' at 0x00E128D8>
>>> drg100.sid
>>> Unhandled exception while debugging...
Traceback (most recent call last):
  File "C:\Zip_Process\py\test2_new.py", line 16, in <module>
    outfile.write(data)
IOError: (22, 'Invalid argument')



More information about the Python-list mailing list