0

With python's zipfile module, I could not open a encrypted zip file and I found out that the compression type is 99. I could open it with WinZip but I would like to automate the procedure with python.

Should I consider using 7zip's command line or is there some way in zipfile module itself to solve the problem? Thanks!

RuntimeError                              Traceback (most recent call last)
<ipython-input-43-4c4765b40715> in <module>()

      3         print (info.filename, info.date_time, info.file_size, info.compress_type)
      4     myzip.setpassword(b'password')
      5     with myzip.open('641903.txt','r') as myfile:<-----
      6         print(myfile.readline()

641903.txt (2018, 6, 26, 11, 59, 50) 342 99

RuntimeError: Bad password for file '641903.txt'
Dharman
  • 30,962
  • 25
  • 85
  • 135
Cindy1011
  • 11
  • 3

1 Answers1

0

You can open password-protected files by simply adding a third parameter

    with myzip.open('641903.txt','r', 'password') as myfile:
        print(myfile.readline() 
Ahmouse
  • 195
  • 1
  • 12
  • Thanks but that does not work. It is basically the same as myzip.setpassword(b'password'). The problem is that AES2 encryption method leads to compression type 99, which cannot be opened by python's zipfile module. 7zip/winzip command line works tho so I will try to call the command line instead. – Cindy1011 Jun 29 '18 at 01:27
  • oh, sorry, my mistake – Ahmouse Jun 29 '18 at 01:59
  • but are you able to use a different encryption? – Ahmouse Jun 29 '18 at 02:00