I am learning how to access a zip file with python BruteForcing. but I am facing a problem when I do that in the zipF in line 11 that is the exception: cannot assign to function call.
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")
Thanks in advance
Advertisement
Answer
You can’t use a break
inside a try-catch
statement. also, you try to assign a function to the file handler. You can use exit(0)
instead of 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")
And you have broken indentation in your program, maybe this is want you want
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")