Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Valid zip file in python

Tags:

python

zip

I uploaded zip folder using file input,but when i check if this zip is valid or not;the result was:is not a valid pkzip file,i don't know what is the specification for valid pkzip. I used this code to check:

form = cgi.FieldStorage() 
file_upload = form['file[]']
if zipfile.is_zipfile(file_upload.filename):
    print "%s is a valid pkzip file" % file_upload.filename
else:
    print "%s is not a valid pkzip file" % file_upload.filename

I don't know why?for example when i upload test.zip,the o/p will be: test.zip is not a valid pkzip file,I need a help.Thanks

like image 245
Computer_Engineer Avatar asked Mar 21 '12 21:03

Computer_Engineer


1 Answers

zipfile.is_zipfile takes a path to a file or a file-like object. You're passing it neither, so it fails.

Ask it about file_upload.file instead.

like image 139
Katriel Avatar answered Sep 21 '22 00:09

Katriel