当我尝试将密码设置为zip文件时出现此错误。以下是我得到的代码/错误。请给我一个正确方法的例子。
代码:
password = "dog"
password = zipfile.setpassword(pwd)
Error received when hitting the password part of the script.
-------------------------------------------
Traceback (most recent call last):
File "C:\Users\Owner\Desktop\ZIP-IT\ZIP IT.py", line 86, in <module>
start()
File "C:\Users\Owner\Desktop\ZIP-IT\ZIP IT.py", line 54, in start
compress()
File "C:\Users\Owner\Desktop\ZIP-IT\ZIP IT.py", line 70, in compress
password = zipfile.setpassword(pwd)
AttributeError: 'module' object has no attribute 'setpassword'
答案 0 :(得分:1)
你在运行Python 2.6 +吗?
将pwd设置为默认密码以提取加密文件。
版本2.6中的新内容。
Python zipfile docs在顶部说他们在ZIP存档中“[支持] 解密加密文件,但目前无法创建加密文件。 “
答案 1 :(得分:-1)
您需要引用特定的zip,而不是模块。
zpf = zipfile.ZipFile('your file path')
password = "dog"
password = zpf.setpassword(pwd)