Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Error email.mime没有属性';mimultipart';_Python_Python 3.x_Email_Raspberry Pi_Raspberry Pi3 - Fatal编程技术网

Python Error email.mime没有属性';mimultipart';

Python Error email.mime没有属性';mimultipart';,python,python-3.x,email,raspberry-pi,raspberry-pi3,Python,Python 3.x,Email,Raspberry Pi,Raspberry Pi3,我正在写一个项目,使用树莓皮3通过Gmail发送电子邮件。该项目在我的笔记本电脑上运行得很好,但当我尝试在Raspberry Pi上运行代码时,会不断报告以下错误: email.mime has no attribute 'MIMEMultipart' 我曾尝试按照其他地方的建议使用pip安装重新安装电子邮件包,但它没有解决这个问题。我特别困惑,因为这目前可以在我的笔记本电脑上使用,但不会在覆盆子Pi 3上使用 我的代码如下: import smtplib import mimetypes i

我正在写一个项目,使用树莓皮3通过Gmail发送电子邮件。该项目在我的笔记本电脑上运行得很好,但当我尝试在Raspberry Pi上运行代码时,会不断报告以下错误:

email.mime has no attribute 'MIMEMultipart'
我曾尝试按照其他地方的建议使用pip安装重新安装电子邮件包,但它没有解决这个问题。我特别困惑,因为这目前可以在我的笔记本电脑上使用,但不会在覆盆子Pi 3上使用

我的代码如下:

import smtplib
import mimetypes
import email
import email.mime.application

FROM = "Sender's address" #This has been removed from this post, but normally contains sender's address
TO = "recipient's address" #This has been removed from this post, but normally contains recipient's address

msg = email.mime.Multipart.MIMEMultipart()
msg['Subject'] = 'Greetings'
msg['From'] = FROM
msg['To'] = TO


body = email.mime.Text.MIMEText("""hi""")
msg.attach(body)


filename= "path+filename" #e.g.(C:/Users/Pictures/pic.jpg)
fp=open(filename,'rb')
att = email.mime.application.MIMEApplication(fp.read(),_subtype="jpg")
fp.close()
att.add_header('Content-Disposition','attachment',filename=filename)
msg.attach(att)

s = smtplib.SMTP('smtp.gmail.com',587)
s.starttls()
s.login('FROM','PASSWORD') #password is actually entered here in my real code, it has been removed from this post
s.sendmail('FROM',['TO'], 
msg.as_string())
s.quit()

提前感谢您提供的任何指导。

这可能是安装问题。 在python安装文件夹中检查Lib/email/mime文件夹中是否有multipart.py文件。
希望这有帮助

我终于自己弄明白了。将导入语句添加到我的代码顶部修复了该问题:

from email.mime.multipart import MIMEMultipart

是的,有一个multipart.py文件。