我让用户输入他们的电子邮件地址。但是,我假设 Python 无法识别特殊字符“@”,但我不确定重新编码/让用户输入如何将该特殊字符识别为字符串的一部分。import smtplibsender_email = "kingofeverything@test.com"rec_email = input('Enter a email to send to: ')password = "Password"SUBJECT = "Subject Line Test"TEXT = "Test Text"message = 'Subject: {}\n\n{}'.format(SUBJECT, TEXT)server = smtplib.SMTP('smtp.gmail.com', 587)server.starttls()server.login(sender_email, password)print("Login success")server.sendmail(sender_email, rec_email, message)print("Email has been ent to ", rec_email)server.quit()我该如何纠正这个问题?#Error: using kingofeverything@gmail.com as my inputTraceback (most recent call last): File "testss.gyp", line 4, in <module> rec_email = input('Enter a email to send to: ') File "<string>", line 1 kingofeverything@gmail.com ^SyntaxError: invalid syntax
1 回答
慕后森
TA贡献1802条经验 获得超5个赞
我怀疑您使用的是 Python 2。在 Python 2 中,尝试在输入字符串上input()
运行。eval()
电子邮件地址不是有效的 python,因此您会收到语法错误。尝试改用raw_input()
。
添加回答
举报
0/150
提交
取消