Python 3.x 属性错误:';字节';对象没有属性';编码';在python 3中
我收到一个错误AttributeError:“bytes”对象没有属性“encode”Python 3.x 属性错误:';字节';对象没有属性';编码';在python 3中,python-3.x,encode,Python 3.x,Encode,我收到一个错误AttributeError:“bytes”对象没有属性“encode” email = 'aashita9317@gmail.com' send_email('Happy Hour Update',message, from_addr=GMAIL_LOGIN, to_addr=email) 上面是它引用的send_email函数,指向msg=MIMEText(message) 请帮忙 def send_email(subject, message, fr
email = 'aashita9317@gmail.com'
send_email('Happy Hour Update',message,
from_addr=GMAIL_LOGIN, to_addr=email)
上面是它引用的send_email函数,指向msg=MIMEText(message)
请帮忙
def send_email(subject, message, from_addr=GMAIL_LOGIN, to_addr=GMAIL_LOGIN):
msg = MIMEText(message)
msg['Subject'] = subject
msg['From'] = from_addr
msg['To'] = to_addr
msg['Reply-To'] = 'happyhours@noreply.com'
上面是它在~\anaconda3\lib\email\mime\text.py中引用的anaconda3文件,位于init(self、\u text、\u subtype、\u charset、policy)文档解释了charset编码的详细信息: 添加标题时,使用例如
msg。添加标题('Subject',Subject)
而不是msg['Subject']=Subject
if _charset is None:
try:
_text.encode('us-ascii')
_charset = 'us-ascii'
except UnicodeEncodeError:
_charset = 'utf-8'