Python:Imaplib 错误

发布于 2024-10-28 06:53:24 字数 1557 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

审判长 2024-11-04 06:53:24

从错误消息网址 (http://mail.google.com/support /bin/answer.py?answer=78754):

确保您的邮件客户端未设置
过于频繁地检查新邮件。如果
您的邮件客户端检查新邮件
每 10 条消息超过一次
分钟,您的客户可能会反复
请求您的用户名和密码。

我猜你连接服务器太频繁了,gmail 会变得可疑。

您似乎还打开了多个 imap 连接,但没有关闭其中任何一个。我不知道你到底想做什么,但我猜有一种更简洁的方法,可能只涉及你不时维护和轮询的一个连接。

From the error message url (http://mail.google.com/support/bin/answer.py?answer=78754):

Make sure your mail client isn't set
to check for new mail too often. If
your mail client checks for new
messages more than once every 10
minutes, your client might repeatedly
request your username and password.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文