472,364 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

zipfile decompress problems

Hi all,

I am new to python and want to create a process to unzip large numbers of
zip files I get from a SOAP application. The files all have a ZIP extention
and can be unzipped using WinZip.

However when I try opening the files using zlib or zipfile modules I get the
following error:

Traceback (most recent call last):
File "<pyshell#88>", line 1, in -toplevel-
file = zipfile.ZipFile("c:\\chessy.zip", "r")
File "C:\Python24\lib\zipfile.py", line 210, in __init__
self._GetContents()
File "C:\Python24\lib\zipfile.py", line 230, in _GetContents
self._RealGetContents()
File "C:\Python24\lib\zipfile.py", line 242, in _RealGetContents
raise BadZipfile, "File is not a zip file"
BadZipfile: File is not a zip file

The code I used in python was:

import zipfile
file = zipfile.ZipFile("c:\\chessy.zip", "r")

I tried to do the same with a zip file I created using WinZip and it worked
fine. I have been searching the web for about two days and haven't found
anything helpful.

Can anyone help with this? I have the zip I can send, however I tried to
send this message with it attached and it didn't get posted.

Cheers,


Jan 16 '06 #1
5 2363
Waguy wrote:
import zipfile
file = zipfile.ZipFile("c:\\chessy.zip", "r")

Use "rb".
--
Giovanni Bajo
Jan 16 '06 #2
I tried that to and it didn't work, got the same message

Thanks though,

"Giovanni Bajo" <ra*****@deveSPAMler.com> wrote in message
news:dq**********@nnrp.ngi.it...
Waguy wrote:
import zipfile
file = zipfile.ZipFile("c:\\chessy.zip", "r")

Use "rb".
--
Giovanni Bajo

Jan 16 '06 #3
Waguy wrote:
I tried that to and it didn't work, got the same message
Thanks though,

Can you send / provide a link to a minimal zip file which reproduces the
problem?
--
Giovanni Bajo
Jan 16 '06 #4

Waguy wrote:
Hi all,

I am new to python and want to create a process to unzip large numbers of
zip files I get from a SOAP application. The files all have a ZIP extention
and can be unzipped using WinZip.

However when I try opening the files using zlib or zipfile modules I get the
following error:

Traceback (most recent call last):
File "<pyshell#88>", line 1, in -toplevel-
file = zipfile.ZipFile("c:\\chessy.zip", "r")
File "C:\Python24\lib\zipfile.py", line 210, in __init__
self._GetContents()
File "C:\Python24\lib\zipfile.py", line 230, in _GetContents
self._RealGetContents()
File "C:\Python24\lib\zipfile.py", line 242, in _RealGetContents
raise BadZipfile, "File is not a zip file"
BadZipfile: File is not a zip file

The code I used in python was:

import zipfile
file = zipfile.ZipFile("c:\\chessy.zip", "r")

I tried to do the same with a zip file I created using WinZip and it worked
fine. I have been searching the web for about two days and haven't found
anything helpful.

Can anyone help with this? I have the zip I can send, however I tried to
send this message with it attached and it didn't get posted.

Cheers,


I'm guessing the downloaded zip files have a faulty magic number or an
odd value that trips up the zipfile module but that winzip ignores.

Another possibility is this: From the documentation:

"This module does not currently handle ZIP files which have appended
comments, or multi-disk ZIP files."

One thing I've noticed is that, when downloading zip files from a
service of some sort, they often seem to have appended comments.
("This file downloaded from www.extremezipfiles.com, blah blah blah.")

Carl Banks

Jan 17 '06 #5
Carl Banks wrote:
Waguy wrote:
I am new to python and want to create a process to unzip large numbers of
zip files I get from a SOAP application. The files all have a ZIP extention
and can be unzipped using WinZip....
Can anyone help with this? ...


Another possibility is this: From the documentation:
"This module does not currently handle ZIP files which have appended
comments, or multi-disk ZIP files."

One thing I've noticed is that, when downloading zip files from a
service of some sort, they often seem to have appended comments.
("This file downloaded from www.extremezipfiles.com, blah blah blah.")


Based on the file Waguy originally sent, you could try using this:

import zipfile, cStringIO
def getzip(filename, ignoreable=100):
try:
return zipfile.ZipFile(filename)
except zipfile.BadZipfile:
original = open(filename, 'rb')
try:
data = original.read()
finally:
original.close()
position = data.rindex(zipfile.stringEndArchive,
-(22 + ignoreable), -20)
coredata = cStringIO.StringIO(data[: 22 + position])
return zipfile.ZipFile(coredata)

--Scott David Daniels
sc***********@acm.org
Jan 19 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LC | last post by:
Hi, I'm having a problem using the zipfile module in Windows 2000 sp4. When I use it to zip a small file it works fine, but large file doesnt. Here's the error msg i get......
19
by: Gerson Kurz | last post by:
AAAAAAAARG I hate the way python handles unicode. Here is a nice problem for y'all to enjoy: say you have a variable thats unicode directory = u"c:\temp" Its unicode not because you want it...
4
by: vincent_delft | last post by:
I've a simple python script that read a directory and put the files into a Zip file. I'm using the os.walk method to get the directory content, I'm creating ZipInfo objects and set "filename",...
1
by: Waitman Gobble | last post by:
Hello, I am new to Python. I am having trouble with zipfile.py. On a Linux machine with python 2.4.2 I have trouble opening a zipfile. Python is complaining about the bit where it does a...
11
by: Hari Sekhon | last post by:
I do import zipfile zip=zipfile.ZipFile('d:\somepath\cdimage.zip') zip.namelist() then either of the two: A) file('someimage.iso','w').write(zip.read('someimage.iso'))
12
by: xamdam | last post by:
Hi fellas, I am experiencing problems reading a 2GB zipfile consisting of multiple zipped files. I found a thread http://mail.python.org/pipermail/python-dev/2005-April/053027.html that mentions...
3
by: towers | last post by:
Hi I'm probably doing something stupid but I've run into a problem whereby I'm trying to add a csv file to a zip archive - see example code below. The csv just has several rows with carriage...
5
by: Neil Crighton | last post by:
I'm using the zipfile library to read a zip file in Windows, and it seems to be adding too many newlines to extracted files. I've found that for extracted text-encoded files, removing all instances...
1
by: John Machin | last post by:
On Jun 4, 8:06 pm, jwesonga <crazylun...@gmail.comwrote: 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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.