Zip File Woes

Robert Rawlins - Think Blue robert.rawlins at thinkbluemedia.co.uk
Wed Jun 27 10:29:28 EDT 2007


Just as an update guys:

 

Before my zip code featured below I have another piece of code that creates
the zip file from a binary string, like this:

 

              #f3 = open("Media/Media.zip", "wb")

              #f3.write(base64.decodestring(MediaBinary))

              #f3.close

 

Now, with that code commented out like that so the unzip code is running on
the file generated last time the code was run it works fine, but if I try
and unzip after the file has been freshly created I get that error, I've
even tried placing a 2 second sleep command in between them and still get
the problems.

 

Thanks guys,

 

Rob

 

From: python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.org
[mailto:python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.org]
On Behalf Of Robert Rawlins - Think Blue
Sent: 27 June 2007 15:10
To: python-list at python.org
Subject: Zip File Woes

 

Hello Guys,

 

I'm having a MASSIVE headache today with zip files, I had it working a while
ago but it all seems to have stopped in the past 30 minutes and I can't
figure out why.

 

I'm simply trying to write a function that will unzip a file, simple as
that. I've currently got this code:

 

Import zipfile

 

              zip = zipfile.ZipFile('Media/Media.zip', 'r')

              unzip(zip)

              zip.close()

 

def unzip(zip):

       for name in zip.namelist():

              newname = 'Media/%s' % (name)

              file(newname, 'wb').write(zip.read(name))

 

Now when I try and run this i get the following error message:

 

  File "/usr/lib/python2.4/zipfile.py", line 242, in _RealGetContents

    raise BadZipfile, "File is not a zip file"

zipfile.BadZipfile: File is not a zip file

 

However, if I copy the zip file off the unit client onto my windows box and
unzip it and it works absolutely perfectly, all the files are extracted as I
would expect, which leads me to think the zip file is fine, and i must just
be missing something in my code.

 

Any ideas guys? I'm tearing my hair out here.

 

Rob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070627/2bba2add/attachment.html>


More information about the Python-list mailing list