PicklingError:不能pickle< class'decimal.Decimal'>:它不是与decimal.Decimal相同的对象 [英] PicklingError: Can't pickle <class 'decimal.Decimal'>: it's not the same object as decimal.Decimal
问题描述
这是我今天在http://filmaster.com上发现的错误> filmaster.com:
PicklingError:Can' t pickle:不一样
对象为decimal.Decimal
这是什么意思?做一个很有意义的...
似乎与django缓存有关,你可以看到这里的整个追溯:
追溯(最近最近的电话):
文件
/home/filmaster/django-trunk/django/core/handlers/base.py ,
line 92,in get_response response =
callback(request,* callback_args,
** callback_kwargs)
文件
/home/filmaster/film20/film20/core/film_views.py,
第193行,在show_film中
workflow.set_data_for_authenticated_user()
$ b $文件
/home/filmaster/film20/film20/core/film_views.py,
行518,
set_data_for_authenticated_user
object_id = self.the_film.parent.id)
文件
/home/filmaster/film20/film20/core/film_helper.py ,
line 179,in get_others_ratings
set_cache(CACHE_OTHERS_RATINGS,
str(object_id)+_+ str(user_id),
userratings)
文件
/home/filmaster/film20/film20/utils/cache_helper.py,
行80,在set_cache中返回
cache.set( CACHE_MIDDLEWARE_KEY_PREFIX
+ full_path,result,get_time(cache_string))
文件
/ home / filmaster / django-trunk / django / core / cache /backends/memcached.py,
第37行,设置
self._cache.set(smart_str(key),value,
timeout或self.default_timeout)
文件
/usr/lib/python2.5/site-packages/cmemcache.py,
第128行,设置val,flags =
self._convert(val)
文件
/usr/lib/python2.5/site-packages/cmemcache.py,
line 112,in _convert val =
pi ckle.dumps(val,2)
PicklingError:不能pickle:不一样
对象为decimal.Decimal
可以从这里下载Filmaster的源代码: bitbucket.org/filmaster/filmaster-test
任何帮助将不胜感激。
Pickle的一个奇怪之处在于,您在腌制其中一个实例之前导入类的方式可以巧妙地更改腌制对象。泡菜要求您在腌制之前和取消分离之前先导入对象。
所以例如:
从ab import c
C = c()
pickler.dump(C)
将使一个微妙的不同对象(有时):
从导入b
C = bc()
pickler.dump (C)
尝试使用导入,这可能会纠正问题。
This is the error I got today at http://filmaster.com">filmaster.com:
PicklingError: Can't pickle : it's not the same object as decimal.Decimal
What does that exactly mean? It does not seem to be making a lot of sense... It seems to be connected with django caching. You can see the whole traceback here:
Traceback (most recent call last):
File "/home/filmaster/django-trunk/django/core/handlers/base.py", line 92, in get_response response = callback(request, *callback_args, **callback_kwargs)
File "/home/filmaster/film20/film20/core/film_views.py", line 193, in show_film
workflow.set_data_for_authenticated_user()File "/home/filmaster/film20/film20/core/film_views.py", line 518, in set_data_for_authenticated_user
object_id = self.the_film.parent.id)File "/home/filmaster/film20/film20/core/film_helper.py", line 179, in get_others_ratings
set_cache(CACHE_OTHERS_RATINGS, str(object_id) + "_" + str(user_id), userratings)File "/home/filmaster/film20/film20/utils/cache_helper.py", line 80, in set_cache return cache.set(CACHE_MIDDLEWARE_KEY_PREFIX + full_path, result, get_time(cache_string))
File "/home/filmaster/django-trunk/django/core/cache/backends/memcached.py", line 37, in set
self._cache.set(smart_str(key), value, timeout or self.default_timeout)File "/usr/lib/python2.5/site-packages/cmemcache.py", line 128, in set val, flags = self._convert(val)
File "/usr/lib/python2.5/site-packages/cmemcache.py", line 112, in _convert val = pickle.dumps(val, 2)
PicklingError: Can't pickle : it's not the same object as decimal.Decimal
And the source code for Filmaster can be downloaded from here: bitbucket.org/filmaster/filmaster-test
Any help will be greatly appreciated.
One oddity of Pickle is that the way you import a class before you pickle one of it's instances can subtly change the pickled object. Pickle requires you to have imported the object identically both before you pickle it and before you unpickle it.
So for example:
from a.b import c
C = c()
pickler.dump(C)
will make a subtly different object (sometimes) to:
from a import b
C = b.c()
pickler.dump(C)
Try fiddling with your imports, it might correct the problem.
这篇关于PicklingError:不能pickle< class'decimal.Decimal'>:它不是与decimal.Decimal相同的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!