I am encountering the following error when I perform a batch.add() with a Gmail API request.
Error:
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()
I tried adding a key : request1["resumable"] = None I tried adding an attribute : request1.resumable = None
I tried searching for other solutions, but I'm stuck. What can I do to resolve this?
The error that I am seeing is occurring during the batch.add(request=request1,request_id=msgID).
To my understanding, the reason why this occurs is because you cannot fetch payloads with batching. Therefore, batching expects resumable to be unassigned with 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()
Notice how its the same, except I removed the .execute() from request1 and request2. Now I no longer receive this error.