[英]Python: Imaplib error
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)
有沒有人有什么想法可以幫助您,還有沒有其他方法可以寫到序列號,謝謝!
從錯誤消息網址( http://mail.google.com/support/bin/answer.py?answer=78754 ):
確保您的郵件客戶端未設置為經常檢查新郵件。 如果您的郵件客戶端每隔10分鍾檢查一次新郵件不止一次,則您的客戶端可能會反復請求您的用戶名和密碼。
我猜想您連接服務器的頻率太高了,Gmail變得可疑了。
您似乎還打開了多個imap連接,而沒有關閉任何一個。 我不知道您到底想做什么,但我想還有一種更簡單的方法,可能只涉及您不時維護和輪詢的一個連接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.