Python循环未运行

时间:2018-11-14 22:05:46

标签: python loops

有人可以帮助我修复以下代码吗?提出问题后,当我回答“是”时,程序的其余部分将无法运行。没有发送电子邮件。 请注意,仅针对此问题,我已将登录数据替换为“ example”。实际代码具有有效的登录详细信息 将变量从“ x”修改为“ answer”

combo = open("combo.txt", "r")
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
count = str(len(combo.readlines(  )))
print ("There are " + count + " amount of combos")
answer = input("Would you like to run this program?: ")


for line in combo:
    pieces = line.split(":")
    email = pieces[0]
    password = pieces[1]
    if answer == "yes":
        msg = MIMEMultipart()
        message = "Dear user, your Spotify account has been hacked\n" + "Your spotify email is: " + email + ", and your password is: " +password + "\n Please change your password ASAP"
        passwordEmail = "example"
        msg['From'] = "example@gmail.com"
        msg['To'] = email
        msg['Subject'] = "Spotify Account Hacked"
        msg.attach(MIMEText(message, 'plain'))
        server = smtplib.SMTP('smtp.gmail.com: 587')
        server.starttls()
        server.login(msg['From'], passwordEmail)
        server.sendmail(msg['From'], msg['To'], msg.as_string())
        server.quit()

1 个答案:

答案 0 :(得分:0)

@Robin Zigmond指出,您尚未声明x

我总是发现,在调试显然无法正常工作的代码时,有用的事情是使用打印语句来检查我认为是正确的内容。在这种情况下,您可以通过执行if来检查print(x)语句之前,以查看值是什么-这将突出显示该变量不存在。