一、运行发送邮件时出现的错误:
此次错误,在解释器3.5中不报,但是在3.7中报错:原因未知
Traceback (most recent call last):
File "E:/Python_Project/second_Two/cs.py", line 25, in <module>
smtpObj = smtplib.SMTP_SSL(mail_host, 465) # 启用SSL发信, 端口一般是465
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\smtplib.py", line 1031, in __init__
source_address)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\smtplib.py", line 261, in __init__
fqdn = socket.getfqdn()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\socket.py", line 676, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc1 in position 2: invalid start byte
在本次报错误的原因是因为在socket模块中获取计算机名时出现的无法解码字节问题
解决方法:将计算机名改成英文(右键我的电脑——属性——更改设置——更改)
name = gethostname():这个函数是获取计算机名字;
_socket这个模块里的一个方法