发现在centos云服务器上(编译方式)安装python3后不能用yagmail,然而在本地(Mac)上是可以的。
错误如下:
Traceback (most recent call last): File "maildebug.py", line 83, in mail yag=yagmail.SMTP(user="caesarbiu@163.com",password="hey123",host="smtp.163.com") File "/usr/local/lib/python3.6/site-packages/yagmail/sender.py", line 78, in __init__ self.login(password) File "/usr/local/lib/python3.6/site-packages/yagmail/sender.py", line 193, in login self.smtp = self.connection(self.host, self.port, **self.kwargs) File "/usr/local/lib/python3.6/site-packages/yagmail/sender.py", line 94, in connection return smtplib.SMTP_SSL if self.ssl else smtplib.SMTP AttributeError: module 'smtplib' has no attribute 'SMTP_SSL'
试过把本地库里的yagmail文件夹以及smtplib.py替换上去,但仍然如此。根据traceback以及smtplib.py代码发现是因为python3不能导入ssl模块。
网上查找解决方法,把源代码里的/Modules/Setup.dist注释掉的四行恢复:
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -crypto
重新编译python3.6,然后就可以import ssl成功,于是SMTP_SSL的错误也就解决了。
然而又出现554错误,是被163邮箱认为是垃圾邮件。。于是屈辱地向网易澄清……(真是好羞耻啊)
随后问题解决~
网友评论