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)
誰かが助けるためのアイデアを持っていますか、そしてシリアルに書く他の方法はありますか、事前に感謝します!