Zip File Woes

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


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/13ec7dc1/attachment.html>


More information about the Python-list mailing list