简体   繁体   English

使用python的zipfile模块设置密码

[英]Setting a password with python's zipfile module

When using the python module zipfile , for some reason I don't know I can't set a password for an archive created. 当使用python模块zipfile ,由于某种原因,我不知道我无法为创建的存档设置密码。

When trying to unzip following empty zip archive, I can do so without prompting a password.. 尝试对空的zip存档进行解压缩时,无需输入密码即可执行此操作。

Here is my code, what's wrong? 这是我的代码,怎么了?

import zipfile  
with zipfile.ZipFile("1.zip","w") as zip:
    zip.setpassword("1234")

From documentation for zipfile module zipfile模块的文档

It supports decryption of encrypted files in ZIP archives, but it currently cannot create an encrypted file. 它支持对ZIP存档中的加密文件进行解密,但是当前无法创建加密文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM