I'm using following code to create password protected zip file, from a file uploaded by user, in my Python34 application using zipFile
. But when I open the zip file from windows, it doesn't ask for the password. I will be using the same password to read zip files from python later on. What am I doing wrong?
Here's my code:
pwdZipFilePath = uploadFilePath + "encryptedZipFiles/"
filePath = uploadFilePath
if not os.path.exists(pwdZipFilePath):
os.makedirs(pwdZipFilePath)
#save csv file to a path
fd, filePath = tempfile.mkstemp(suffix=source.name, dir=filePath)
with open(filePath, 'wb') as dest:
shutil.copyfileobj(source, dest)
#convert that csv to zip
fd, pwdZipFilePath = tempfile.mkstemp(suffix=source.name + ".zip", dir=pwdZipFilePath)
with zipfile.ZipFile(pwdZipFilePath, 'w') as myzip:
myzip.write(filePath)
myzip.setpassword(b"tipi")