Python Bruteforcing zip文件无法分配给函数调用
Posted
技术标签:
【中文标题】Python Bruteforcing zip文件无法分配给函数调用【英文标题】:Python Bruteforcing zip file cannot assign to function call 【发布时间】:2020-08-17 13:23:58 【问题描述】:我正在学习如何使用 python BruteForcing 访问 zip 文件。但是当我在第 11 行的 zipF 中这样做时,我遇到了一个问题 这是一个例外:不能分配给函数调用。
import zipfile
zipF = zipfile.ZipFile
zipName = input("File path : ")
passwordFile = open("14MillionPass.txt","r")
for passw in passwordFile.readlines():
ps = str(int(passw))
ps = ps.encode()
try:
with zipF.ZipFile(zipName) as myzip(): #the error is here
myzip.extractAll(pwd = ps)
print("Password found \n -> 0 is 1 password".format(ps,zipName))
break
except:
print("password not found")
提前致谢
【问题讨论】:
【参考方案1】:您不能在try-catch
语句中使用break
。此外,您尝试将函数分配给文件处理程序。你可以用exit(0)
代替break
try:
with zipfile.ZipFile(zipName) as myzip:
myzip.extractAll(pwd = ps)
print("Password found \n -> 0 is 1 password".format(ps,zipName))
exit(0) # successful exit
except:
print("password not found")
而且你在你的程序中破坏了缩进,也许这是你想要的
import zipfile
zipName = input("File path : ")
passwordFile = open("14MillionPass.txt","r")
for passw in passwordFile.readlines():
ps = str(int(passw))
ps = ps.encode()
try:
with zipfile.ZipFile(zipName) as myzip:
myzip.extractAll(pwd = ps)
print("Password found \n -> 0 is 1 password".format(ps,zipName))
break
except:
print("password not found")
【讨论】:
以上是关于Python Bruteforcing zip文件无法分配给函数调用的主要内容,如果未能解决你的问题,请参考以下文章
python 怎么读取网络zip字节流,并保存到本地zip文件中?