smtp - Python utf-8 error -
when tried send email using python,i met error,here 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 output 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, 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
you can try name.decode()
solve problem non-ascii characters.
Comments
Post a Comment