python-2.7 - 无法登录 gmail - imaplib.error - ALERT 请通过您的网络浏览器登录

标签 python-2.7 email gmail-api gmail-imap

我正在尝试登录 gmail 并阅读 python 包中的消息。但是得到一个错误:[ALERT] 请通过您的网络浏览器登录:https://support.google.com/mail/accounts/answer/78754 (失败)

import imaplib
import email

m = imaplib.IMAP4_SSL("imap.gmail.com", 993)
m.login("username@gmail.com","password")
m.select('"[Gmail]/All Mail"')

result, data = m.uid('search', None, "ALL") # search all email and return uids
if result == 'OK':
    for num in data[0].split():
        result, data = m.uid('fetch', num, '(RFC822)')
    if result == 'OK':
        email_message = email.message_from_bytes(data[0][1])    # raw email text including headers
        print('From:' + email_message['From'])

m.close()
m.logout()

最佳答案

这对我有用:

关于python-2.7 - 无法登录 gmail - imaplib.error - ALERT 请通过您的网络浏览器登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45886791/

相关文章:

django - 如何使用 django send_mail 显示名称而不是电子邮件地址?

node.js - 邮戳模板 : dynamic variable with html processed as text instead of html

android - 使用 Android 的 Gmail API 访问

python - 如何使用 python 日志记录模块打印多行日志?

python - django-wkhtmltopdf 给出 "[Error 2] The system cannot find the file specified"?

selenium - Jenkins :无法发送电子邮件

php - Gmail API : 400 bad request when trying to send an email (PHP code)

python - scikit-learn 中对象没有属性,如何访问它?

Python在每个元音前添加字符串

gmail-api - GMail v1 API Users.messages 结果与逻辑 AND/OR 上的 Web UI 不同