猿问

为什么在我运行此电子邮件程序时会显示“扫描字符串文字时 EOL”?

我创建了一个 python 脚本来使用 gmail 帐户发送电子邮件。我使用的是 Python 3.7,但是当我去运行该程序时,它"EOL while scanning string literal"在消息框中说。任何人都可以解决这个问题吗?告诉我你是否找到了解决它的方法。


import smtplib

server = smtplib.SMTP('smtp.gmail.com', 587)


#Next, log in to the server

server.login("youremailusername", "password")


#Send the mail

msg = "

Hello!" # The /n separates the message from the headers

server.sendmail("you@gmail.com", "target@example.com", msg)


慕雪6442864
浏览 304回答 2
2回答

繁星点点滴滴

EOL = 行尾此错误告诉您它在扫描字符串文字时遇到“行尾”。正常的字符串不应是多行。使用三重引号来解决这个问题:msg = """Hello!"""

杨魅力

你有一个错字msg = ""仅当存在未结束的字符串时才会弹出错误。
随时随地看视频慕课网APP

相关分类

Python
我要回答