Python 由于pickle错误,在Django缓存API中设置对象失败
我试图在Django缓存API中手动设置一个对象,但失败了(我想是因为酸洗?) 该对象由第三方提供给我,我的代码为:Python 由于pickle错误,在Django缓存API中设置对象失败,python,django,memcached,pickle,Python,Django,Memcached,Pickle,我试图在Django缓存API中手动设置一个对象,但失败了(我想是因为酸洗?) 该对象由第三方提供给我,我的代码为: 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
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))
当我运行这个时,我得到一个错误
Can't pickle <type 'etree._Element'>: import of module etree failed
in - cache.set("user_list_ds", user_list, 10*60) # 10 minutes
无法pickle:导入模块etree失败
in-cache.set(“用户列表”,用户列表,10*60)#10分钟
我对python非常陌生,我想知道如何最好地解决这个问题,我是否需要先pickle一些东西?您似乎需要安装,因为
pickle
操作尝试导入etree
模块,但失败
更新:进一步看,您是否确实在尝试缓存文档节点?如果您试图缓存节点中的数据,可能需要对当前存储在
user\u list
中的值进行一些处理。如果您是对的,我必须将试图缓存的数据类型更改为普通python列表。