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.
JavaScript
x
17
17
1
import zipfile
2
3
zipF = zipfile.ZipFile
4
zipName = input("File path : ")
5
passwordFile = open("14MillionPass.txt","r")
6
for passw in passwordFile.readlines():
7
ps = str(int(passw))
8
ps = ps.encode()
9
10
try:
11
with zipF.ZipFile(zipName) as myzip(): #the error is here
12
myzip.extractAll(pwd = ps)
13
print("Password found n -> {0} is {1} password".format(ps,zipName))
14
break
15
except:
16
print("password not found")
17
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
JavaScript
1
8
1
try:
2
with zipfile.ZipFile(zipName) as myzip:
3
myzip.extractAll(pwd = ps)
4
print("Password found n -> {0} is {1} password".format(ps,zipName))
5
exit(0) # successful exit
6
except:
7
print("password not found")
8
And you have broken indentation in your program, maybe this is want you want
JavaScript
1
15
15
1
import zipfile
2
3
zipName = input("File path : ")
4
passwordFile = open("14MillionPass.txt","r")
5
for passw in passwordFile.readlines():
6
ps = str(int(passw))
7
ps = ps.encode()
8
try:
9
with zipfile.ZipFile(zipName) as myzip:
10
myzip.extractAll(pwd = ps)
11
print("Password found n -> {0} is {1} password".format(ps,zipName))
12
break
13
except:
14
print("password not found")
15