AttributeError:' str'对象没有属性' extractall'从蛮力中拉出拉链

时间:2018-02-12 01:03:06

标签: python zip zipfile brute-force

我不知道为什么我会收到以下错误,我知道密码在早些时候强制使用之后仍然赢了,但是我不能解压缩文件。

需要将我的文件解压缩到目录/ tmp

所以我错过任何明显的东西吗?

输出错误:

Traceback (most recent call last):
File "/tmp/usercode.py", line 45, in <module>
myZip.extractall("/tmp",pwd = str(password))
AttributeError: 'str' object has no attribute 'extractall'

代码:

import zipfile
from zipfile import ZipFile
import zipfile

zf = zipfile.ZipFile('/tmp/myfile.zip')
for x in range(0,139):
  #Legacy for loop now
  password = "past"
  print(password)
  for filename in [ 'textinhere.txt' ]:
        myZip = "textinhere.txt"
        try:
                myZip.extractall("/tmp",pwd = str(password))
        except KeyError:
                print 'ERROR: Did not find %s in zip file' % filename
        else:
                print filename, ':'
                print repr(data)

1 个答案:

答案 0 :(得分:2)

您在这里定义一个字符串: myZip = "textinhere.txt"

exctractallZipFile类的方法。因此,您需要首先构造ZipFile的实例,假设此名称是您希望用作ZipFile实例的路径的文件:

myZip = ZipFile("textinhere.txt")

...只有这样才能拨打myZip.extractall(...