Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8384 > unrolled thread

unzip problem

Started by"Ahmed, Shakir" <shahmed@sfwmd.gov>
First post2011-06-24 10:55 -0400
Last post2011-06-25 03:55 +1000
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  unzip problem "Ahmed, Shakir" <shahmed@sfwmd.gov> - 2011-06-24 10:55 -0400
    Re: unzip problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-24 15:33 +0000
      RE: unzip problem "Ahmed, Shakir" <shahmed@sfwmd.gov> - 2011-06-24 13:23 -0400
        RE: unzip problem steve+comp.lang.python@pearwood.info - 2011-06-25 03:55 +1000

#8384 — unzip problem

From"Ahmed, Shakir" <shahmed@sfwmd.gov>
Date2011-06-24 10:55 -0400
Subjectunzip problem
Message-ID<mailman.371.1308928216.1164.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

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')

 

 

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()

********************************

 

[toc] | [next] | [standalone]


#8385

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2011-06-24 15:33 +0000
Message-ID<4e04ae66$0$29975$c3e8da3$5496439d@news.astraweb.com>
In reply to#8384
On Fri, 24 Jun 2011 10:55:52 -0400, Ahmed, Shakir wrote:

> Hi,
> 
> 
>  
> I am getting following error message while unziping a .zip file. Any
> help or idea is highly appreciated.

How do you know it is when unzipping the file? Maybe it is, or maybe it 
isn't. The line giving the error has *two* IO operations, a read and a 
write. Either one could give IOError.

outfile.write(z.read(name))
IOError: (22, 'Invalid argument')

The first thing is to isolate what is causing the error:

data = z.read(name)
outfile.write(data)

Now you can be sure whether it is the read or the write  which causes the 
error.

Secondly, find out what the argument is. Assuming it is the read, try 
this:

print repr(name)

Can you open the zip file in Winzip or some other zip utility? Does it 
need a password? 

I see you do this:

fh = open('T:\\test\\*.zip', 'rb')

Do you really have a file called *.zip? I find that very hard to 
believe... as I understand it, * is a reserved character in Windows and 
you cannot have a file with that name.

My guess is that the actual error is when you try to open the file in the 
first place, before any unzipping takes place, but you've messed up the 
line numbers (probably by editing the file after importing it).


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#8389

From"Ahmed, Shakir" <shahmed@sfwmd.gov>
Date2011-06-24 13:23 -0400
Message-ID<mailman.373.1308936224.1164.python-list@python.org>
In reply to#8385
On Fri, 24 Jun 2011 10:55:52 -0400, Ahmed, Shakir wrote:

> Hi,
> 
> 
>  
> I am getting following error message while unziping a .zip file. Any
> help or idea is highly appreciated.

How do you know it is when unzipping the file? Maybe it is, or maybe it 
isn't. The line giving the error has *two* IO operations, a read and a 
write. Either one could give IOError.

outfile.write(z.read(name))
IOError: (22, 'Invalid argument')

The first thing is to isolate what is causing the error:

data = z.read(name)
outfile.write(data)

Now you can be sure whether it is the read or the write  which causes
the 
error.

Secondly, find out what the argument is. Assuming it is the read, try 
this:

print repr(name)

Can you open the zip file in Winzip or some other zip utility? Does it 
need a password? 

I see you do this:

fh = open('T:\\test\\*.zip', 'rb')

Do you really have a file called *.zip? I find that very hard to 
believe... as I understand it, * is a reserved character in Windows and 
you cannot have a file with that name.

My guess is that the actual error is when you try to open the file in
the 
first place, before any unzipping takes place, but you've messed up the 
line numbers (probably by editing the file after importing it).


-- 
Steven

>>
The problem is happening when it is coming to write option.

The * is not the real name of the zip file, I just hide the name.

[toc] | [prev] | [next] | [standalone]


#8392

Fromsteve+comp.lang.python@pearwood.info
Date2011-06-25 03:55 +1000
Message-ID<4e04cf8d$0$29981$c3e8da3$5496439d@news.astraweb.com>
In reply to#8389
Ahmed, Shakir wrote:

> The problem is happening when it is coming to write option.
> 
> The * is not the real name of the zip file, I just hide the name.

Please don't waste our time by showing us fake code that doesn't do what you
say it does.

You said that "The script is here", but that was not true, was it? What you
showed us was not the script you were running. What other changes,
deliberate or accidental, did you make?

If you are going to edit the script to make it simpler (a good idea!),
please run it first to make sure you still get the same error.



-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web