我正在尝试登录 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()
最佳答案
这对我有用:
- 开启https://myaccount.google.com/lesssecureapps
- 如果仍然出现错误,请访问 https://accounts.google.com/b/4/DisplayUnlockCaptcha (其中 4 是您登录帐户列表中的 authuser id),然后单击
Continue
关于python-2.7 - 无法登录 gmail - imaplib.error - ALERT 请通过您的网络浏览器登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45886791/