由于pickle错误,在Django缓存API中设置对象失败 [英] Setting an object in the Django cache API fails due to pickle error
问题描述
我正在尝试在Django缓存API中手动设置一个对象,但是它失败了(我认为是由于酸洗?) 该对象是由第三方提供给我的,我的代码是:
I'm trying to manually set an object in the Django cache API but it fails (i think due to pickling?) The object is given to me by a third party, my code is:
def index(request, template_name="mytemplate.htm"):
user_list = cache.get("user_list_ds")
if user_list is None:
# this is the expensive bit I'm trying to cache
# given to me by a third part
user_list = graffiti.user_list("top", 100).responseObj().blocks()
cache.set("user_list_ds", user_list, 10*60) # 10 minutes
return render_to_response(template_name, { 'user_list' : user_list,}, context_instance = RequestContext(request))
运行此命令时出现错误;
When I run this I get an error;
Can't pickle <type 'etree._Element'>: import of module etree failed
in - cache.set("user_list_ds", user_list, 10*60) # 10 minutes
我是python的新手,我想知道如何最好地解决这个问题,我需要先腌制一些东西吗?
I'm very new to python, and I'm wondering how best to resolve this, do i need to pickle something first?
推荐答案
It appears that you need to install ElementTree
, because the pickle
operation tries and fails to import the etree
module.
更新:进一步看,您实际上是在尝试缓存文档节点吗?如果要尝试从该节点缓存数据,则可能需要对当前存储在user_list
中的值进行一些处理.
UPDATE: Looking at it further, are you actually trying to cache document nodes? If you're trying to cache the data from the node, you probably need to do some processing of the value you're currently storing in user_list
.
这篇关于由于pickle错误,在Django缓存API中设置对象失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!