'RuntimeError: Bad password for file

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'


Solution 1:[1]

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

    with myzip.open('641903.txt','r', 'password') as myfile:
        print(myfile.readline() 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ahmouse