【问题标题】:gmail python client api import message shows Syntax errorgmail python客户端api导入消息显示语法错误
【发布时间】:2018-06-04 23:13:27
【问题描述】:

gmail python api service.users().messages().import 显示语法错误这里是代码行

mgg = services.users().messages().import(userId='me', raw=base64.urlsafe_b64encode(mime_msg.as_string()), labelIds=mime_msg.get('labelIds')).execute()

错误显示在import(的括号中

如果我将import 更改为importee 之类的内容,则会显示此错误 AttributeError: 'Resource' object has no attribute 'importee' 所以看起来和它有关?

Python 保留关键字

我还在 gmail api 中提交了错误,这里是 google issue tracker 的链接

【问题讨论】:

  • 有时,在语法错误时,问题出现在错误消息显示的 before 行中。给我们看Minimal, Complete, and Verifiable Example
  • 寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:如何创建最小、完整和可验证的示例。
  • @DavidG DalmTo。好的

标签: python gmail-api google-api-python-client


【解决方案1】:

我发现用户cdlearya comment 有帮助。解决方法是我将_ 附加到importservice.users().messages().import_() 正在工作。虽然我仍然在 Google 问题跟踪器中打开了问题。

【讨论】:

    【解决方案2】:

    是的,由于 import 在 Python 中是一个保留字,因此 Google python 库会在 API 方法名称后附加一个“_”。使用:

    service.users().messages().import_(....)
    

    文档目前(截至 2017 年底)不正确,有一个未解决的问题需要修复。见:https://github.com/google/google-api-python-client/issues/408

    【讨论】:

    • 感谢您提供更多信息。但是既然你迟到了那么我的答案,所以我应该选择我的答案???
    猜你喜欢
    • 2019-10-05
    • 2014-06-18
    • 2023-01-26
    • 1970-01-01
    • 2016-03-31
    • 2018-11-16
    • 2018-12-04
    • 2011-11-03
    • 2015-12-03
    相关资源
    最近更新 更多