How do I setpassword to compressed zip files in Python
I get this error when I try to set a password to a zip file. Below is the code/error I get. Please give me an example of the correct wa开发者_JS百科y to do it.
- This is just the password part of the script... the entire script is to long to post.
Code:
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'
Are you running Python 2.6+?
ZipFile.setpassword(pwd)
Set pwd as default password to extract encrypted files.
New in version 2.6.
The Python zipfile docs say at the top that they "[support] decryption of encrypted files in ZIP archives, but it currently cannot create an encrypted file."
You need to reference the particular zip, instead of the module.
zpf = zipfile.ZipFile('your file path')
password = "dog"
password = zpf.setpassword(pwd)
精彩评论