Skip to content Skip to sidebar Skip to footer

Google App Engine Payload Object

How to send a class object in the payload of a task in python? I want to send an object in the parameters of a task. When I use simplejson, I get the error: Object is not serializa

Solution 1:

The problem was with the type of data that was unloaded. I casted it to type str and everything seemed to work properly. I just changed it to

icfg = Matrix2D_icfg("icfg") #declaring objecticfg_compress = pickle.dumps(icfg) #to pickleicfg = pickle.loads(str(icfg_compress)) # to unload

Solution 2:

Have you looked at the deferred library? It's designed for exactly this, and takes care of serialization and deserialization for you.

Solution 3:

This is a part of my task queueing service. It just posts a list to another task to break the project up into manageable parts. It's just part of it but you should get most of the idea for what you need to do.

To save it:

from django.utils import simplejson as json

.... stuff happens

index = 0
            current_list = []
            whileindex < len(item_list):
                ifindex+500 < len(item_list):
                    for item in item_list[index:index+500]:
                        current_list.append(item.item_number)
                    jsondump = json.dumps(current_list)
                    taskqueue.add(url = '/queuer', 
                                  headers = {'Content-Type':'application/json'},
                                  payload = jsondump)

To load it:

from django.utils import simplejson as json

    classTaskQueuer(webapp.RequestHandler):
    defpost(self):
        request = self.request.body
        task_list = json.loads(request)

Post a Comment for "Google App Engine Payload Object"