【问题标题】:IMAP error when accessing gmail from command line从命令行访问 gmail 时出现 IMAP 错误
【发布时间】:2015-11-18 13:32:48
【问题描述】:

我正在编写一个简单的脚本,通过 python 脚本从 gmail 读取未读邮件。我有以下脚本,但是当我运行 python 脚本时,我得到下面标记的 IMAP 错误。对此问题的任何帮助表示赞赏。

我在我的 gmail 设置中启用了 IMAP。是否有任何其他配置需要我注意才能使其正常工作?

import imaplib
obj = imaplib.IMAP4_SSL('imap.gmail.com','993')
obj.login('username','password')
obj.select()
obj.search(None,'Unseen')

其中,username 是我的 gmail 用户名,password 是我的 gmail 帐户的密码。

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    obj.login('ashwin.tumma23@gmail.com',password)
  File "/usr/lib/python2.7/imaplib.py", line 519, in login
    raise self.error(dat[-1])
imaplib.error: [ALERT] Please log in via your web browser:    
https://support.google.com/mail/accounts/answer/78754 (Failure)

【问题讨论】:

  • that URL 有一些诊断问题的建议。你看过那个清单吗?您是否使用现有的 IMAP 客户端(mutt/Apple Mail/Thunderbird/whatever)通过 IMAP 成功访问了 GMail?
  • 你检查support.google.com/mail/accounts/answer/78754了吗?您是否启用了两因素身份验证?
  • 不,我没有启用两因素身份验证

标签: python email gmail-api gmail-imap


【解决方案1】:

visibleman 的回答是正确的。作为替代方案,您可能希望将脚本切换为使用Gmail API 而不是 IMAP。 Gmail API 使用 OAuth 2.0 进行更安全的身份验证。 Gmail API 也是比 IMAP 更容易使用的协议。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题。 我不确定哪一步最终解决了它,但这是我所做的:

    似乎在此之后,您可以再次禁用“不太安全”,它仍然有效。

    【讨论】:

      猜你喜欢
      • 2015-06-13
      • 2012-02-26
      • 2012-02-08
      • 2016-08-23
      • 1970-01-01
      • 2012-10-22
      • 2012-05-28
      • 1970-01-01
      • 2021-12-31
      相关资源
      最近更新 更多