Batching Python Gmail API : AttributeError: 'dict' object has no attribute 'resumable'

Batching Python Gmail API : AttributeError: 'dict' object has no attribute 'resumable'

我在使用 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) 期间发生的。

据我了解,出现这种情况的原因是您无法通过批处理获取有效负载。因此,批处理期望使用 None.

取消分配可恢复

  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()

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