简体   繁体   中英

'str' object is not callable error

How do I fix my run-time error in the code below?

#!/usr/bin/env python3
import zipfile
def extract(zipf, pwd):
    try:
        zipf.extractall(psw=(pwd))
        return
    except :
        return
def main():
    zipf = zipfile.is_zipfile("dave.zip")
    pwdfile=open("pwdlist.txt", "r")
    for line in pwdfile.readlines():
        psw = line.strip()("\n")
        guess = extract(zipf, psw)
        if guess:
            print ("[+] Password is : %s"%(psw) + ("\n"))
            exit(0)
if __name__ == '__main__':
    main()

Error:

psw = line.strip()("\\n") TypeError: 'str' object is not callable

Change:

psw = line.strip()("\n") 

To

psw = line.strip("\n")

Note, line.strip() returns a string which you then try to call, so it's something like:

>>> "I'm a string"()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable

Or perhaps more clearly:

>>> string_object = "I'm a string"
>>> string_object()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable

line.split() is a function call that returns a string. You then tried to call that string as a function with an argument of "\\n".

If you're trying to split on line breaks, you need

line.split("\n")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM