473,378 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 2427
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.