google app engine - Gmail API Python: RequestTooLargeError: The request to API call datastore_v3.Put() was too large -
i getting following error batch request gmail api on google app engine:
requesttoolargeerror: request api call datastore_v3.put() large.
from other questions on stackoverflow understand problem has memcache. nevertheless don't know how solve issue, since coming if run 1 request per batch , before can content of email (like compressing it).
my code looks follows:
count = 0 #start new batch request after every 1000 requests batch = batchhttprequest(callback=get_items) in new_items: batch.add(service.users().messages().get(userid=email, id=i), request_id=str(count)) count += 1 if count % 1000 == 0: n in range(0, 5): try: batch.execute(http=http) break except exception e: if n < 4: time.sleep((2 ** n) + random.randint(0, 1000) / 1000) else: raise batch = batchhttprequest(callback=get_items) if count % 1000 != 0: n in range(0, 5): try: batch.execute(http=http) break except exception e: if n < 4: time.sleep((2 ** n) + random.randint(0, 1000) / 1000) else: raise
what possible solution?
edit
adding callback function
def get_items(request_id, response, exception): if exception not none: print 'an error occurred: %s' % exception else: save_messages = request_id.split('/', 2)[1] email = request_id.split('/', 2)[2] in_reply_to = '' m_id = '' r in response['payload']['headers']: if r['name'].lower() == 'message-id': m_id = r.get('value') elif r['name'].lower() == 'in-reply-to': in_reply_to = r.get('value') elif r['name'].lower() == 'from': sender, t_t = stripemails(r.get('value'), none, none, true, email, false, false) if m_id: incoming = gmail(id=m_id) #skip if exists else: logging.info(response) logging.exception('no message id detect') return incoming.email = email incoming.response = json.dumps(response) incoming.put()
by savings large text item jsonproperty compressed=true problem solved.
Comments
Post a Comment