Python 类型错误:';MIMEText';对象不可调用

Python 类型错误:';MIMEText';对象不可调用,python,python-3.x,email,mime,Python,Python 3.x,Email,Mime,我有以下代码(代码片段) 在最后一行(178),我得到以下错误: 回溯(最近一次调用上次):文件 “/Users/adieball/Dropbox/Multiverse/Programming/python/repositories/cloudologist/exam.py”, 第198行,在 main()文件“/Users/adieball/Dropbox/Multiverse/Programming/python/repositories/cloudologist/exam.py”, 第17

我有以下代码(代码片段)

在最后一行(178),我得到以下错误:

回溯(最近一次调用上次):文件 “/Users/adieball/Dropbox/Multiverse/Programming/python/repositories/cloudologist/exam.py”, 第198行,在 main()文件“/Users/adieball/Dropbox/Multiverse/Programming/python/repositories/cloudologist/exam.py”, 第178行,主 msg.attach(part)TypeError:“MIMEText”对象不可调用

我有点困惑,因为我已经在上面的一行中调用了MIMEText(msg.attach=MIMEText(HTML\u CONTENT,'HTML'))

非常感谢您提供的任何帮助

这里:

msg.attach = MIMEText(HTML_CONTENT, 'html')
您可以使用
MIMEText
实例使用
MIMEMultipart.attach()
方法创建阴影。因此,当您到达此处时:

msg.attach(part)
实际上,您正试图调用这个
MIMEText
实例,实际上,它是不可调用的(它是
MIMEText
类,它与所有python类一样是可调用的)

你当然想替换

msg.attach = MIMEText(HTML_CONTENT, 'html')


我有点担心文件名
exam.py
。如果这是一个实际的、现场的课堂考试,在这里提问会作弊。@Blacksilver没有,我只是称它为exam.py,因为脚本会为参加内部考试的人创建证书(pdf上的报告实验室)。
msg.attach = MIMEText(HTML_CONTENT, 'html')
msg.attach(MIMEText(HTML_CONTENT, 'html'))