【问题标题】:RuntimeError: Bad password for filePython zipfile:RuntimeError:文件密码错误
【发布时间】:2018-06-27 02:10:03
【问题描述】:

使用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'

【问题讨论】:

  • 你没有传入密码参数吗?

标签: python zipfile 7zip


【解决方案1】:

可以通过简单地添加第三个参数来打开受密码保护的文件

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

【讨论】:

  • 谢谢,但这不起作用。它与 myzip.setpassword(b'password') 基本相同。问题是AES2加密方式导致压缩类型为99,python的zipfile模块无法打开。 7zip/winzip 命令行可以工作,所以我会尝试调用命令行。
  • 哦,对不起,我的错
  • 但是您可以使用不同的加密方式吗?
猜你喜欢
  • 2018-12-28
  • 2015-01-08
  • 2019-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-23
相关资源
最近更新 更多