How to store etree object that can't be pickled

519 views
Skip to first unread message

Ian W. Scott

unread,
Aug 29, 2015, 1:40:10 AM8/29/15
to web2py-users
I have a parsed lxml.etree object that I need to persist from one request to the next so that users can interact with it. The problem is that etree objects can't be pickled, so when I try to store it in session I get a PicklingError. I just tried using memcache instead, but it seems to use pickling as well and raises the same PicklingError.

Is there any way to store an un-picklable object (maybe in memory somehow?) so that it's accessible to web2py on subsequent requests?

Thanks,

Ian

Leonel Câmara

unread,
Aug 29, 2015, 10:03:42 PM8/29/15
to web2py-users
Well you can use etree.tostring and save that. Another alternative is to put it in cache ram which does not pickle.

Ian W. Scott

unread,
Aug 29, 2015, 10:21:41 PM8/29/15
to web2py-users


On Saturday, August 29, 2015 at 10:03:42 PM UTC-4, Leonel Câmara wrote:
Well you can use etree.tostring and save that. Another alternative is to put it in cache ram which does not pickle.

I'd like to avoid serializing out to a string because I'd then have to do the parsing over again on the next request. How would I go about putting it in a ram cache? (I looked at memcache, but it looks like the Python wrapper uses pickling). If you can just point me to the relevant package(s) for this kind of caching I can read the docs. But I've found my google searches to be less than helpful on this.

Thanks,

Ian

Leonel Câmara

unread,
Aug 30, 2015, 8:34:27 AM8/30/15
to web2py-users
I'm not talking about memcache I'm talking about web2py's included cache.ram.

See this book chapter to learn how to use it:
Reply all
Reply to author
Forward
0 new messages