求教:smtp发送邮件编码错误

用qq的smtp发送邮件包编码错误,请问怎么解决,已设置了utf-8

import smtplib
from email.mime.text import MIMEText

smtpserver="smtp.qq.com"
port = 465
sender="2453*******[email protected]"
psw="refezmt**********djgd"
receiver="2453******[email protected]"

subject='你好'
body='

错误

' msg=MIMEText(body,"html","utf-8") msg["from"]=sender msg["to"]=receiver msg["subject"]=subject smtp=smtplib.SMTP() smtp.connect(smtpserver) smtp=smtplib.SMTP_SSL(smtpserver,port) smtp.login(sender,psw) smtp.sendmail(sender,receiver,msg.as_string()) smtp.quit()

报错如下

Traceback (most recent call last):
  File "E:/python_project/bixia/send.py", line 18, in 
    smtp=smtplib.SMTP()
  File "H:\python\lib\smtplib.py", line 261, in __init__
    fqdn = socket.getfqdn()
  File "H:\python\lib\socket.py", line 676, in getfqdn
    hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 0: invalid start byte

你可能感兴趣的:(求教:smtp发送邮件编码错误)