开发者

How to pass a 'BeautifulSoup.Tag' object inside http post request in google app engine?

I have a BeautifulSoup.Tag object which I want to transfer in an http post request. Specifically this is a request a task in google app engine would perform.

This is the code:

taskqueue.add(url='/maintenance', method='post', params={'row': row})

When I receive the request on the other end,开发者_如何学Python the parameter row is a unicode string. How do I get my original object back? As I undersand json eval won't work for this kind of object, so is there another solution Am I compelled to pass simple objects only?


Hmmm. Beautiful soup is kind of an evaluator. So I can send the object's html and the reuse beautiful soup.

I did it this way:

taskqueue.add(url='/maintenance', params={'element': str(myObject)})

and then reused soup inside the task itself:

payload = self.request.get('element')

soup = BeautifulSoup(payload)


I guess you can try python's pickle functions to pass the value by string. http://docs.python.org/library/pickle.html

Another way will be use memcache. just store the value to memcache and pass the key to tasks.

for example

memcache.set("some_random_generate_key", row)
taskqueue.add(url='/maintenance', method='post', params={'row_key': "some_random_generate_key"})

then in the task handlers, just get the value from memcache again. (in fact, google appengine also used pickle to store value in memcache)

memcache.get(row_key)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜