Discuss / Python / 为什么会出现这个问题

为什么会出现这个问题

Topic source

from email.mime.text import MIMEText msg = MIMEText('hello, send by Python...', 'plain', 'utf-8')

from_addr = input('From: ') password = input('Password: ')

输入收件人地址:

to_addr = input('To: ')

输入SMTP服务器地址:

smtp_server = input('SMTP server: ')

import smtplib server = smtplib.SMTP(smtp_server, 25) # SMTP协议默认端口是25 server.set_debuglevel(1) server.login(from_addr, password) server.sendmail(from_addr, [to_addr], msg.as_string()) server.quit()

Traceback (most recent call last):

File "<ipython-input-6-03fd52fcf2b0>", line 1, in <module> runfile('C:/Users/ /Desktop/email.py', wdir='C:/Users/ /Desktop')

File "C:\2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile execfile(filename, namespace)

File "C:\2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/ /Desktop/email.py", line 35, in <module> server = smtplib.SMTP(smtp_server, 25) # SMTP协议默认端口是25

File "C:\2\lib\smtplib.py", line 260, in init fqdn = socket.getfqdn()

File "C:\2\lib\socket.py", line 673, in getfqdn hostname, aliases, ipaddrs = gethostbyaddr(name)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 0: invalid start byte


  • 1

Reply