You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用yagmail获取OAuth2令牌及发送邮件时遇权限认证问题

使用yagmail发送邮件的OAuth2认证问题及相关疑问

一、yagmail OAuth2认证报错情况

尝试用Python的yagmail库发送邮件时,在OAuth2令牌获取环节遇到格式不兼容问题,试了三种方法均出错:

  • 在Google API控制台创建Client ID并下载credentials.json,系统生成token.json后能正常打印Gmail账户标签,但执行yag.send()时触发错误:

    TypeError: refresh_authorization() got an unexpected keyword argument 'token'
    问题出在token.json包含不符合yagmail预期的token键。

  • 按相关帖子要求编辑token.json,移除多余键并给字段添加google_前缀后,出现错误:

    ValueError: Authorized user info was not in the expected format, missing fields refresh_token, client_id, client_secret
    系统不认可添加的google_前缀。

  • 去掉google_前缀重新编辑token.json后,又出现权限范围不足的错误:

    An error occurred: <HttpError 403 when requesting https://gmail.googleapis.com/gmail/v1/users/me/labels?alt=json returned "Request had insufficient authentication scopes"

二、相关疑问

  1. 刚接触OAuth2,不确定在处理yagmail认证时有没有遗漏关键技巧?
  2. 想了解GitHub与Stack Overflow的关联和区别是什么?

内容的提问来源于stack exchange,提问作者kramsman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 06:10:34