简体   繁体   中英

Python utf-8 error

When I tried to send an email using python,I met this error,here is the code:

from_addr = '*@163.com'
password = '*'
to_addr = '*@qq.com'
smtp_server = 'smtp.163.com'

import smtplib
server = smtplib.SMTP(smtp_server, 25) 
server.set_debuglevel(1)
server.login(from_addr, password)
server.sendmail(from_addr, [to_addr], msg.as_string())
server.quit()

then the output is it:

Traceback (most recent call last):
  File "C:\Users\Desktop\smtp.py", line 17, in <module>
    smtp = smtplib.SMTP()
  File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 260, i
    fqdn = socket.getfqdn()
  File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 673, in
    hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 0: invalid start byte

您可以尝试使用name.decode()解决非ASCII字符的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM