此Bug出现在smtp.SMTP_SSL()类
Bug产生原因
当我们在SMTP_SSL类实例化的时候直接传入host及port时,可以正常连接服务器。但如果先实例化SMTP_SSL类后,再调用connect()方法时就会报 server_hostname cannot be an empty string or start with a leading dot. 的错误
import smtplib
smtp_server = "smtp.163.com"
con1 = smtplib.SMTP_SSL(smtp_server, 465)
此Bug产生的原因是因为在SMTP_SSL类实例化的时候的时候有一个基类的初始化,如果你传了host和port,在SMTP基类里,self._host就是传入的host。但如果你先实例化再调用connect()方法,基类的self._host就是默认参数值空""。
BUG的解决
如图所示,把SMTP_SSL类_get_socket方法中的的server_hostname=self._host改成server_hostname=host即可。