python - ZipFile complains, is there a way around using the zipfile module? -


The problem I am trying to uncompress some MMS messages sent is that sometimes it works , And not others. And when it does not work, the Python Zipfile module complains and says that this is a bad ZIP file. But the zipfile is not correct by using the Unix Unzip command.

This is what got

  zippedfile = open ('% stemp / tempfile.zip'% settings.MEDIA_ROOT, 'W +') zippedfile.write (string ) Z = zipfile.ZipFile (zippedfile)  

I am using 'w' and writing a string for it, the string in the base 64 decode string representation is a zip file Of

Then I do this:

  filelist = z.infolist () images = [] in the file list: raw_mimetype = mimetypes.guess_type (F.filename) [0] ] If raw_mimetype: mimetype = raw_mimetype.split ('/') [0] Other: mime type = 'unknown' if mime-type == 'image': images.append (f.filename)  

In this way I got a list of all the images in the zip file. But it does not always work because the zipfile module complains about some files.

Is there a way to do this, without using the zipfile module?

Can I use somehow unzip the Unix command instead of the zip file, and then withdraw the same thing from the collection all the images?

"post-text" itemprop = "text">

You should open the file in binary mode while typing in your life. That is, you should use

  zippedfile = open ('% stemp / tempfile.zip'% settings.MEDIA_ROOT, 'wb +')  

Comments