python - PicklingError : Can't pickle <class 'decimal.Decimal' >: it's not the same object as decimal. 十进制

标签 python django pickle

这是我今天在 filmmaster.com:

遇到的错误
PicklingError: Can't pickle <class
'decimal.Decimal'>: it's not the same
object as decimal.Decimal

这到底是什么意思?好像没有多大意义…… 它似乎与 django 缓存有关。您可以在此处查看整个回溯:

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 <class
'decimal.Decimal'>: it's not the same
object as decimal.Decimal

电影大师的源代码可以从这里下载:bitbucket.org/filmaster/filmaster-test

任何帮助将不胜感激。

最佳答案

在 jupyter notebook 中运行时出现此错误。我认为问题在于我使用的是 %load_ext autoreload autoreload 2。重新启动我的内核并重新运行解决了这个问题。

关于python - PicklingError : Can't pickle <class 'decimal.Decimal' >: it's not the same object as decimal. 十进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1412787/

相关文章:

python - Django 模型的额外参数

python - 如何 pickle 继承的异常?

python - sklearn将模型保存到磁盘,但只获取数组

python - pickle .PicklingError : args[0] from __newobj__ args has the wrong class with hadoop python

python - `scipy.stat.distributions` 的内置概率密度函数是否比用户提供的慢?

python - 从 Arduino 项目中读取串行数据 (pySerial)

Python 和 Django OperationalError (2006, 'MySQL server has gone away')

python - Django Admin 修改模型继承

python - 如何去掉解析的html页面中的\ufeff

python - Python中的Excel解析并形成字典