import serial
import imaplib
from time import sleep
IMAP_SERVER='imap.gmail.com'
IMAP_PORT=993
ser= serial.Serial ('/dev/ttyACM0',9600)
while True:
M = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT)
rc, resp = M.login('user@gmail.com', 'Password')
print rc, resp
M.select()
for msg_num in M.search("INBOX", "UNDELETED")[1][0].split():
msg = M.fetch('1', '(BODY.PEEK[TEXT])')
try:
String = msg[1][0][1][139:148]
except TypeError:
continue
print String
if String == "This is just a test...":
ser.write('0')
sleep(1)
我是 python 编程的新手,上面的 python 代码是我用于我想做的程序的代码。当我在终端中运行此程序时,我会收到我已验证我的帐户的响应,然后它会显示字符 139 和 161 之间的消息,在示例电子邮件中如下所示:
This is just a test...
这在终端中打印出来。几次后,程序检查了我的电子邮件,出现了这个错误:
Traceback (most recent call last):
File "/home/wilson/Desktop/Best_Gmail_yet _Dont_touch.py", line 11, in <module>
rc, resp = M.login('user@gmail.com', 'password')
File "/usr/lib/python2.6/imaplib.py", line 500, in login
raise self.error(dat[-1])
imaplib.error: [ALERT] Web login required: http://mail.google.com/support /bin/answer.py?answer=78754 (Failure)
有没有人有任何想法可以提供帮助,有没有其他方法可以写连续剧,在此先感谢!