【问题标题】:Authentication Error when trying to access a gmail business account to read emails - using IMAP_4SSL尝试访问 gmail 企业帐户以阅读电子邮件时出现身份验证错误 - 使用 IMAP_4SSL
【发布时间】:2020-03-30 09:24:59
【问题描述】:

我正在尝试访问一个 gmail 帐户,以便阅读电子邮件并保存附加到这些电子邮件的 PDF。我编写了代码,当我在我的个人 gmail 帐户 (something@gmail.com) 上对其进行测试时,它运行良好,但现在我正在尝试为这个新地址 (reporting@company.com,这是一家 gmail 业务)帐户)我的代码甚至无法连接。

我收到一条错误消息说

Error: b’[AUTHENTICATIONFAILED] Invalid Credentials (Failure)’

我知道登录电子邮件和密码都是正确的。我已经从 Google API 页面下载了 credentials.json 文件。

我的代码如下:

Mail = imaplib.IMAP4_SSL(“imap.gmail.com”)
Mail.login(“reporting@company.com”,’password’)

【问题讨论】:

    标签: python gmail-imap


    【解决方案1】:

    如果您仍在代码中使用密码,那么您需要让您的用户访问enable Less Secure Apps,或者如果他们正在使用两步验证,create an App Password

    但是,更好的方法是使用 OAuth 而不是密码。如果您已经从 Google Developers Console 下载了 credentials.json 文件,那么您已经完成了第一步。 :) 谷歌有a guide to use OAuth with IMAP in Python,还有a code sample(参见那里的TestImapAuthentication方法)。

    【讨论】:

    • 感谢您的回复!结果证明,我必须在 Google 帐户上启用两步验证。
    【解决方案2】:

    我所要做的就是在 google 帐户上启用两步验证。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-26
      • 2017-02-26
      • 2019-03-20
      • 2019-01-16
      • 2020-07-06
      • 2017-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多