Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.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 3.x 属性错误:';字节';对象没有属性';编码';在python 3中_Python 3.x_Encode - Fatal编程技术网

Python 3.x 属性错误:';字节';对象没有属性';编码';在python 3中

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

我收到一个错误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, 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'