【问题标题】:Batching Python Gmail API : AttributeError: 'dict' object has no attribute 'resumable'批处理 Python Gmail API:AttributeError:“dict”对象没有属性“resumable”
【发布时间】:2021-09-11 03:08:45
【问题描述】:

我在使用 Gmail API 请求执行 batch.add() 时遇到以下错误。

错误:

if request.resumable is not None:
AttributeError: 'dict' object has no attribute 'resumable'

for searchResultPart in searchResultParts: 
    batch = BatchHttpRequest() 
    batch2 = BatchHttpRequest()
    for msgID in searchResultPart: #Loop through each messageID
        request1 = service.users().messages().get(userId=userID, id=msgID).execute()
        request1.update({"resumable" : None}) #TRIED THIS DOES NOT WORK
        request2 = service.users().messages().modify(userId=userID, id=msgID, body={'removeLabelIds': ['UNREAD']}).execute()
        batch.add(request=request1,request_id=msgID) #Fetch the message
        batch2.add(request=request2,request_id=msgID) #Mark the fetched messages as read
    batch.execute() 
    batch2.execute()

我尝试添加一个密钥:request1["resumable"] = None 我尝试添加一个属性:request1.resumable = None

我尝试寻找其他解决方案,但我被困住了。我该怎么做才能解决这个问题?

我看到的错误是在 batch.add(request=request1,request_id=msgID) 期间发生的。

据我了解,发生这种情况的原因是您无法通过批处理获取有效负载。因此,批处理期望 resumable 未分配为 None。

【问题讨论】:

  • 好的,问题出在最后的 .execute() 上。

标签: python python-3.x gmail gmail-api


【解决方案1】:

  for searchResultPart in searchResultParts: 
      batch = BatchHttpRequest() 
      batch2 = BatchHttpRequest()
      for msgID in searchResultPart: #Loop through each messageID
          request1 = service.users().messages().get(userId=userID,id=msgID)
          body = {'removeLabelIds': ['UNREAD']}
          request2 = service.users().messages().modify(userId=userID, id=msgID, body=body)
          batch.add(request=request1, callback=self.theEmailCallback,request_id=msgID) #Fetch the message
          batch2.add(request=request2,request_id=msgID) #Mark the fetched messages as read
      batch.execute() 
      batch2.execute()

注意它是一样的,除了我从request1和request2中删除了.execute()。现在我不再收到此错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-26
    • 2020-03-09
    • 2020-09-11
    • 1970-01-01
    • 2018-06-22
    • 2018-10-13
    • 2019-08-02
    相关资源
    最近更新 更多