Python:Imaplib 错误
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('[email protected]', '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 和 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('[email protected]', '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)
是否有人有任何想法可以提供帮助,是否有其他方法可以写入序列号,提前致谢!
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('[email protected]', '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)
I'm a new beginner in python programming and the above python code is one that I'm using for a program I want to do. When I run this in a terminal I get the response that I have authenticated my account and then it displays the message between characters 139 & 161, which is the following in the example email:
This is just a test...
This is printed out in the terminal. After a few times the program checks my email this error comes out:
Traceback (most recent call last):
File "/home/wilson/Desktop/Best_Gmail_yet _Dont_touch.py", line 11, in <module>
rc, resp = M.login('[email protected]', '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)
Does anyone have any ideas to help out and is there any other way to write to serial, Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从错误消息网址 (http://mail.google.com/support /bin/answer.py?answer=78754):
我猜你连接服务器太频繁了,gmail 会变得可疑。
您似乎还打开了多个 imap 连接,但没有关闭其中任何一个。我不知道你到底想做什么,但我猜有一种更简洁的方法,可能只涉及你不时维护和轮询的一个连接。
From the error message url (http://mail.google.com/support/bin/answer.py?answer=78754):
I'd guess you're connecting to the server too frequently, and gmail gets suspicious.
You also appear to be opening multiple imap connections without closing any of them. I don't know exactly what you're trying to do but I'd guess there's a more parsimonious way, probably involving just one connection that you maintain and poll from time to time.