Gmail IMAP身份验证 - imaplib.authenticate只需3个参数(给定4个参数) [英] Gmail IMAP Authentication -- imaplib.authenticate takes exactly 3 args (4 given)

查看:751
本文介绍了Gmail IMAP身份验证 - imaplib.authenticate只需3个参数(给定4个参数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试从我的网络应用程序启用Gmail IMAP访问功能。现在,用户可以授予对Web应用程序的访问权,成功检索并存储用户的令牌和秘密。但是,当我尝试验证IMAP连接以检索电子邮件时,它会给出以下错误:

I'm trying to enable Gmail IMAP access from my web application. Right now, users can grant access to the web application, successfully retrieving and storing the user's token and secret. But, when I try to authenticate the IMAP connection for retrieving emails, it gives the following error:

TypeError: authenticate() takes exactly 3 arguments (4 given)

这里是代码(非常简单):

Here is the code (very simple):

import oauth2 as oauth
import imaplib

consumer = oauth.Consumer('token','secret')
token = oauth.Token('token','secret')

url = "https://mail.google.com/mail/b/username@gmail.com/imap/"
conn = imaplib.IMAP4_SSL('imap.googlemail.com')
conn.debug = 4
conn.authenticate(url,consumer,token)

为了避免实际的 authenticate 函数,但无济于事:

I tried backing out a little bit to avoid the actual authenticate function, but to no avail:

imaplib.IMAP4_SSL.authenticate(conn,'XOAUTH',lambda x: oauth.build_xoauth_string(url,consumer,token))

这给了我类似的输出:

29:03.17 > CMIK6 AUTHENTICATE XOAUTH
29:03.27 < CMIK5 BAD Too many arguments provided s68if10067716yhm.26
29:03.27 BAD response: Too many arguments provided s68if10067716yhm.26

我不确定问题可能是什么。为什么 authenticate 函数认为有4个参数? oauth字符串是否可以解释为多个字符串,即不能正确转义?他们有斜线,下划线,加号​​,但没有逗号。

I'm not sure what the problem could be. Why would the authenticate function think there were 4 arguments? Could the oauth strings be interpreted as multiple strings, i.e., not escaped properly? They have slashes, underscores, plus signs, but no commas.

其他想法?

推荐答案

使用oauth2进行IMAP时,您需要将它与 oauth2.clients.imap 结合使用,以便:

When using oauth2 for IMAP, you need to use it in conjunction with oauth2.clients.imap, so:

import oauth2 as oauth
import oauth2.clients.imap as imaplib

# the rest of your code as it was

您可以在此页面底部看到一个示例: https://github.com/simplegeo/python-oauth2

You can see an example towards the bottom of this page: https://github.com/simplegeo/python-oauth2

这篇关于Gmail IMAP身份验证 - imaplib.authenticate只需3个参数(给定4个参数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆