繁体   English   中英

Python zipfile:RuntimeError:文件密码错误

[英]Python zipfile: RuntimeError: Bad password for file

使用python's zipfile模块,我无法打开加密的zip文件,发现压缩类型为99。我可以使用WinZip打开它,但我想使用python自动执行该过程。

我应该考虑使用7zip的命令行,还是zipfile模块本身有某种方法可以解决此问题? 谢谢!

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'

您只需添加第三个参数即可打开受密码保护的文件

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM