我想导入smtplib到我正在编写的sikuli脚本,这样Sikuli可以在测试完成后自动发送电子邮件。
但是,我遇到一个问题,Sikuli无法在Python中找到smtplib模块,我确信它已经安装并位于Python 27/Lib目录中。下面是我正在使用的代码。我使用SikuliX 1.1.0和Python2.7。
import smtplib
sender = '<email address hidden>'
receivers = ['<email address hidden>']
message = """From: From Person <email address hidden>
To: To Person <email address hidden>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('test.com.hk')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except:
print "Error: unable to send email"当我在Sikuli IDE中运行它时,它给了我:
错误脚本停止发送第2行中的错误ImportError (没有模块名为utils )错误--错误源第一行:模块(函数)语句46: smtplib ()导入email.utils错误-回溯
有人能帮忙吗?谢谢
发布于 2015-10-13 06:02:08
在您的email.py中有一个名为sys.path的文件,它隐藏了标准库的email包--甚至可能是您正在测试的脚本。
https://docs.python.org/2/library/email.html
若要修复,请使用其他任何内容作为模块/文件名。
akg@limbo:~/scratch.d/20151012-stack33095084$ cat email.py
import smtplib
sender = '<email address hidden>'
receivers = ['<email address hidden>']
message = """From: From Person <email address hidden>
To: To Person <email address hidden>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('test.com.hk')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except:
print "Error: unable to send email"
akg@limbo:~/scratch.d/20151012-stack33095084$ python email.py
Error: unable to send email
Traceback (most recent call last):
File "email.py", line 1, in <module>
import smtplib
File "/usr/lib/python2.7/smtplib.py", line 46, in <module>
import email.utils
ImportError: No module named utils
akg@limbo:~/scratch.d/20151012-stack33095084$ mv email.py anything_but_email.py
akg@limbo:~/scratch.d/20151012-stack33095084$ python anything_but_email.py
Error: unable to send emailhttps://stackoverflow.com/questions/33095084
复制相似问题