【发布时间】:2020-07-13 11:43:10
【问题描述】:
email = 'aashita9317@gmail.com'
send_email('Happy Hour Update',message,
from_addr=GMAIL_LOGIN, to_addr=email)
我收到一个错误 AttributeError: 'bytes' object has no attribute 'encode'
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'
上面是它所引用的 send_email 函数,指向 msg = MIMEText(message) 请帮忙
if _charset is None:
try:
_text.encode('us-ascii')
_charset = 'us-ascii'
except UnicodeEncodeError:
_charset = 'utf-8'
上面是它在 init(self, _text, _subtype, _charset, policy) 中的 ~\anaconda3\lib\email\mime\text.py 中引用的 anaconda3 文件
【问题讨论】:
标签: python-3.x encode