提问人:Sentinal 提问时间:9/27/2023 最后编辑:Sentinal 更新时间:9/27/2023 访问量:29
python 3.7 中通过 smtp 发送电子邮件的属性错误
Attribute error in sending email through smtp in python 3.7
问:
我在这个问题中隐藏了ID和密码。但是,gmail密码是在之后生成的 开启两步验证并生成应用密码。
错误-- AttributeError:模块“smtplib”没有属性“SMTP”
import smtplib
email = "*****@gmail.com"
password = "*****"
with smtplib.SMTP("smtp.gmail.com", port=587) as connection:
connection.starttls()
connection.login(user=email, password=password)
connection.sendmail(from_addr=email,
to_addrs="*****@yahoo.com",
msg="Subject:Hello\n\nThis is the body of the email"
)
答:
0赞
Goku - stands with Palestine
9/27/2023
#1
当 Python 发现与模块的循环依赖关系时,通常会发生此错误。smtplib
如果您的 python 脚本被命名为 或 ,则 Python 在执行库的 import 语句时会尝试导入您的文件。smtplib.py
email.py
smtplib
因此,它会创建一个部分初始化的模块,如果您的脚本没有名为 smtp 的属性,您将遇到此错误。
解决方案:
将发送 python 脚本的电子邮件重命名为除 或 以外的名称smtplib.py
email.py
评论