views:

21

answers:

1

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 way 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'
A: 

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."

Nick T
How was the code colorized like that?
Noah Brainey
Colorized like what? In your original post another member (pyfunc) edited it using the code formatting tool (adds 4 spaces before all the lines) which marks it as "code", then some fancy JavaScript colors it.
Nick T