AttributeError:'bytes'对象没有属性'encode'Mimetext错误

时间:2020-04-01 20:55:25

标签: python python-3.x

这是函数,错误是指向行msg = MIMEText(message)的。我在这里得到mimetext的属性错误。有另一种写那行的方法吗?

def send_email(subject, message, from_addr=GMAIL_LOGIN, to_addr=GMAIL_LOGIN):
    msg = MIMEText(message)
    msg.add_header('Subject', subject)
    msg.add_header('From', from_addr)
    msg.add_header('To', to_addr)
    msg.add_header('Reply-To', 'happyhours@noreply.com')

在引用它的下面

email = 'aashita9317@gmail.com'
send_email('Happy Hour Update',message,
            from_addr=GMAIL_LOGIN, to_addr=email)

0 个答案:

没有答案