由于 pickle 错误,在 Django 缓存 API 中设置对象失败
我试图在 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
# 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
我对 python 很陌生,我想知道如何最好地解决这个问题,我需要先腌制一些东西吗?
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
I'm very new to python, and I'm wondering how best to resolve this, do i need to pickle something first?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您需要安装
ElementTree
,因为pickle
操作尝试导入etree
模块,但失败。更新:进一步观察,您实际上是在尝试缓存文档节点吗?如果您尝试缓存来自节点的数据,您可能需要对当前存储在
user_list
中的值进行一些处理。It appears that you need to install
ElementTree
, because thepickle
operation tries and fails to import theetree
module.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
.