python - Offlineimap XOAUTH2: xoauth2handler got: {u'error_description': u'Bad Request', u'error': u'invalid_grant'}
问题描述
对于喜欢视觉的人:
对于喜欢文字的人:
OfflineIMAP 7.1.5
Licensed under the GNU GPL v2 or any later version (with an OpenSSL exception)
imaplib2 v2.57 (system), Python v2.7.17, OpenSSL 1.1.1 11 Sep 2018
Account sync Gmail:
*** Processing account Gmail
Establishing connection to imap.gmail.com:993 (Remote)
XOAUTH2 authentication failed: xoauth2handler got: {u'error_description': u'Bad Request', u'error': u'invalid_grant'}
ERROR: All authentication types failed:
XOAUTH2: xoauth2handler got: {u'error_description': u'Bad Request', u'error': u'invalid_grant'}
*** Finished account 'Gmail' in 0:01
ERROR: Exceptions occurred during the run!
ERROR: All authentication types failed:
XOAUTH2: xoauth2handler got: {u'error_description': u'Bad Request', u'error': u'invalid_grant'}
Traceback:
File "/usr/share/offlineimap/offlineimap/accounts.py", line 283, in syncrunner
self.__sync()
File "/usr/share/offlineimap/offlineimap/accounts.py", line 359, in __sync
remoterepos.getfolders()
File "/usr/share/offlineimap/offlineimap/repository/IMAP.py", line 452, in getfolders
imapobj = self.imapserver.acquireconnection()
File "/usr/share/offlineimap/offlineimap/imapserver.py", line 558, in acquireconnection
self.__authn_helper(imapobj)
File "/usr/share/offlineimap/offlineimap/imapserver.py", line 431, in __authn_helper
"failed:\n\t%s"% msg, OfflineImapError.ERROR.REPO)
这是我的.offlineimaprc
[general]
accounts = Gmail
[Account Gmail]
localrepository = Local
remoterepository = Remote
synclabels = yes
labelsheader = X-Keywords
[Repository Local]
type = GmailMaildir
localfolders = ~/emails
nametrans = lambda f: '[Gmail]/' + f if f in ['Drafts', 'Starred', 'Important', 'Spam', 'Trash', 'All Mail', 'Sent Mail$
[Repository Remote]
type= Gmail
auth_mechanisms = XOAUTH2
oauth2_client_id = xxxxxx.apps.googleusercontent.com
oauth2_client_secret = xxxxxxxxx
oauth2_request_url = https://accounts.google.com/o/oauth2/token
oauth2_refresh_token = xxxxxx
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
nametrans = lambda f: f.replace('[Gmail]/', '') if f.startswith('[Gmail]/') else f
解决方案
我最近遇到了同样的问题 - 添加remoteuser = myself@gmail.com
到配置(与不依赖 OAuth 时相同)有帮助
推荐阅读
- spring - Spring Boot:与@JoinColumn 的 ManyToOne 关系保持外键为空
- javascript - 在 Google Chrome 扩展程序中使用弹出窗口时如何将事件发送到后端
- python - Python:使用随机密码保护 PDF 并保存文件名-密码
- php - 如何使用同一个表中的 sql 创建一个具有三层深度的嵌套数组
- python - 在 jupyter notebook 中调试 numpy 数组时解析时出现意外 EOF
- discord - 当我回答“是”时,什么都没有发生?
- java - 对于压缩图像的请求,是关心请求的速度还是压缩图像的大小更好?
- python - 从剧本中解析场景
- python - 如何从不同的列表中随机抽取样本并将它们组合成一个新列表?
- excel - 如何将具有多个工作表的工作簿的每一行复制到它自己的具有多个工作表的工作簿中?