我对这种语言很陌生,在通过 python 发送电子邮件时遇到了一些麻烦,我的代码如下所示:
import smtplib
server=smtplib.SMTP("smtp.gmail.com",587)
server.starttls()
server.login('username','password')
message = "hi there"
server.sendmail('username', 'username', message)
server.quit()
我的系统是:
Win32 上的 Python 3.7.0(v3.7.0:1bf9cc5093,2018 年 6 月 27 日,04:06:47)[MSC v.1914 32 位(Intel)]
我得到的输出是:
Traceback (most recent call last):
File "C:\pythonfiles\testmail - kopia.py", line 6, in <module>
server=smtplib.SMTP("smtp.gmail.com",587)
File "C:\python\lib\smtplib.py", line 261, in __init__
fqdn = socket.getfqdn()
File "C:\python\lib\socket.py", line 676, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in
position 4: unexpected end of data
我的计算机名由字母 é 组成,我可以对此做些什么吗?我已经通过记事本将文件保存为UTF-8。
有任何想法吗?
干杯安德烈