473,691 Members | 2,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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#8 8>", line 1, in -toplevel-
file = zipfile.ZipFile ("c:\\chessy.zi p", "r")
File "C:\Python24\li b\zipfile.py", line 210, in __init__
self._GetConten ts()
File "C:\Python24\li b\zipfile.py", line 230, in _GetContents
self._RealGetCo ntents()
File "C:\Python24\li b\zipfile.py", line 242, in _RealGetContent s
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.zi p", "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 2448
Waguy wrote:
import zipfile
file = zipfile.ZipFile ("c:\\chessy.zi p", "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*****@deveSP AMler.com> wrote in message
news:dq******** **@nnrp.ngi.it. ..
Waguy wrote:
import zipfile
file = zipfile.ZipFile ("c:\\chessy.zi p", "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#8 8>", line 1, in -toplevel-
file = zipfile.ZipFile ("c:\\chessy.zi p", "r")
File "C:\Python24\li b\zipfile.py", line 210, in __init__
self._GetConten ts()
File "C:\Python24\li b\zipfile.py", line 230, in _GetContents
self._RealGetCo ntents()
File "C:\Python24\li b\zipfile.py", line 242, in _RealGetContent s
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.zi p", "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.BadZipf ile:
original = open(filename, 'rb')
try:
data = original.read()
finally:
original.close( )
position = data.rindex(zip file.stringEndA rchive,
-(22 + ignoreable), -20)
coredata = cStringIO.Strin gIO(data[: 22 + position])
return zipfile.ZipFile (coredata)

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

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

Similar topics

1
2919
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... --------------------------------------------------------------------- dynamite4_db_archive.py", line 45, in ? file.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED) File "C:\Python22\lib\zipfile.py", line 426, in write zinfo.file_size))
19
11880
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 to, but because its for example read from _winreg which returns unicode. You do an os.listdir(directory). Note that all filenames returned are now unicode. (Change introduced I believe in 2.3).
4
3270
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", ... to what os.walk give me. .... And it works!!!! BUT!!
1
4209
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 seek(-22,2). Looks to me like zipfile.py is trying to come back 22 bytes from the end of file. # python
11
7593
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
4663
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 a problem on the writing side, does such a problem exist on a reading side? I am using 2.4.1, perhaps there is a fix in a later version?
3
4215
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 return line feeds (CRLF). However after adding it to an archive and then decompressing the line endings have been converted to just line feeds (LF).
5
5159
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 of '\r' in the extracted file seems to fix the problem, but I can't find an easy solution for binary files. The code I'm using is something like: from zipfile import Zipfile z = Zipfile(open('zippedfile.zip'))
1
2186
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 traceback will do for now, so: The error says that you are trying to seek 22 bytes backwards from the
0
8533
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8795
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7624
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6457
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4322
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2966
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1954
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.