相关疑难解决方法(0)

Python代码创建密码加密的zip文件?

创建密码加密的zip文件的Python代码是什么?我可以在命令行上使用系统使用一些apt-get'able实用程序.

python

13
推荐指数
3
解决办法
4万
查看次数

创建受密码保护的zip文件Python

我正在使用以下代码在的Python34应用程序中根据用户上传的文件创建受密码保护的zip文件zipFile。但是,当我从Windows打开zip文件时,它不会要求输入密码。稍后,我将使用相同的密码从python读取zip文件。我究竟做错了什么?

这是我的代码:

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")
Run Code Online (Sandbox Code Playgroud)

python django zipfile python-3.x

4
推荐指数
2
解决办法
8227
查看次数

标签 统计

python ×2

django ×1

python-3.x ×1

zipfile ×1