I've been trying to implement a very simple script, extracting zip files that are password protected. I have created a simple zip file (test.zip) with the password "1234" containing 2 text files (1.txt, 2.txt) and i wrote this script:
import zipfile
PASSWORD = "1234"
zip = zipfile.ZipFile("test.zip", "r")
zip.setpassword(PASSWORD)
zip.extractall()
zip.close()
and i'm getting the following Runtime error:
Traceback (most recent call last):
File "test.py", line 7, in <module>
zip.extractall()
File "/usr/lib/python2.7/zipfile.py", line 962, in extractall
self.extract(zipinfo, path, pwd)
File "/usr/lib/python2.7/zipfile.py", line 950, in extract
return self._extract_member(member, path, pwd)
File "/usr/lib/python2.7/zipfile.py", line 993, in _extract_member
source = self.open(member, pwd=pwd)
File "/usr/lib/python2.7/zipfile.py", line 934, in open
raise RuntimeError("Bad password for file", name)
RuntimeError: ('Bad password for file', <zipfile.ZipInfo object at 0x1f3f2a8>)
I've tried iterating using "zip.namelist()" and the "extract()" method + specifying the exact parameters as follows:
zip.extract(<file_name>, path=<path>, pwd=<password>)
with no luck :( I know about the security issue with "extractall()" and in my complete code i will have verification prior to the extracting process, i'm just trying to figure out what am i doing wrong?
Thanks for the help in advance!