gpt4 book ai didi

python - Gmail IMAP 身份验证 - imaplib.authenticate 恰好需要 3 个参数(给定 4 个)

转载 作者:行者123 更新时间:2023-11-30 23:48:33 27 4
gpt4 key购买 nike

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

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

这是代码(非常简单):

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功能,但无济于事:

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 字符串是否可以解释为多个字符串,即未正确转义?它们有斜杠、下划线、加号,但没有逗号。

还有其他想法吗?

最佳答案

使用oauth2进行IMAP时,需要与oauth2.clients.imap结合使用,所以:

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

# the rest of your code as it was

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

关于python - Gmail IMAP 身份验证 - imaplib.authenticate 恰好需要 3 个参数(给定 4 个),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7963820/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com