0

I have a question to the zipfile library in python 2.7.12. It seems that if I try to extract a .zip that is password protected, an exception is thrown.

I am able to extract a zipdirectory without password protection with python, and I have confirmed that i am able to extract it on my linux system without python and the right passphrase.

I will now post the unzipping process on my local console:

>>> import zipfile
>>> z = zipfile.ZipFile("folder.zip","r")
>>> z.extractall(pwd="taddel")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/zipfile.py", line 1040, in extractall
    self.extract(zipinfo, path, pwd)
  File "/usr/lib/python2.7/zipfile.py", line 1028, in extract
    return self._extract_member(member, path, pwd)
  File "/usr/lib/python2.7/zipfile.py", line 1082, in _extract_member
    with self.open(member, pwd=pwd) as source, \ 
  File "/usr/lib/python2.7/zipfile.py", line 1007, in open
    raise RuntimeError("Bad password for file", name)
RuntimeError: ('Bad password for file', <zipfile.ZipInfo object at 0x7f31cd1c3370>)
>>>

I could give you the script I was developing at, but broken down it does nothing more than trying to dictonary-force the password and split everything into nice threads. I know this IS the right password for this file, cause i made it myself. I also already tried to .strip("\n") and to convert to ("utf-8").

I also know I do not have to specify a folder in which everything is extracted into, cause with a not password protected zip-archieve this code works perfectly fine.

How can I fix this? Or even, are there updated python libs available if the standart ones are not working?

Dharman
  • 30,962
  • 25
  • 85
  • 135
numb.3rs
  • 11
  • 2
  • Have you made absolutely sure that `pwd` is correct? Have you tested it with a different archive? – Nils Werner Sep 29 '16 at 13:59
  • hi Mr. Werner. Yes I made sure pwd is correct, to be honest I have not tested it with a different archive, but I created the archive myself, and I deleted it and created it 3 times in a row, always with this password.... – numb.3rs Sep 30 '16 at 19:49
  • It seems this https://stackoverflow.com/questions/7483138/python-the-zipfile-module-doesnt-seem-to-work-with-passwords?rq=1 could be a duplicate question asked 5 years ago. They say that the encryption mode is essential, and to try out 7-zip's encription mode. I will fiddle around a bit and let you know about the behaviour – numb.3rs Sep 30 '16 at 19:55

0 Answers0