- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从我的 GAE Python 应用程序中的这行代码中收到 PicklingError:
deferred.defer(email_voters_begin, ekey, voter_list)
这三个参数是:
当此行作为我的测试的一部分执行时(使用 webtest 和 nosegae),我收到以下错误:
Traceback (most recent call last):
[...]
File "/Users/joneill/OpenSTV/OpenSTV/trunk/OpaVote-HR/tasks.py", line 29, in init_voters_and_send_email
deferred.defer(email_voters_begin, ekey, voter_list)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/deferred/deferred.py", line 249, in defer
pickled = serialize(obj, *args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/deferred/deferred.py", line 221, in serialize
return pickle.dumps(curried, protocol=pickle.HIGHEST_PROTOCOL)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1374, in dumps
Pickler(file, protocol).dump(obj)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
[...]
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 396, in save_reduce
save(cls)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 753, in save_global
(obj, module, name))
PicklingError: Can't pickle <class 'google.appengine.ext.blobstore.blobstore.BlobInfo'>: it's not the same object as google.appengine.ext.blobstore.blobstore.BlobInfo
请注意,deferred.defer()
中传递的 Voter
实体没有 BlobReference
属性,但 Voter
实体确实具有指向另一个具有 BlobReference
属性的实体的 ReferenceProperty
属性。我不认为任何 BlobInfo 对象都会成为 pickle 的一部分,但错误表明其中包含一个对象。
当我使用开发服务器从浏览器窗口运行相同的代码时,不会发生此错误。
我对如何调试这个感到困惑,任何想法将不胜感激。
最佳答案
发生这种情况的原因可能是您已检索至少一个 Voter 对象的 ReferenceProperty
。一旦取消引用 ReferenceProperty
,模型实例就会缓存它。 Pickling 也会 pickle 任何缓存的对象,因此它会尝试序列化 Voter
实例、引用的实例及其 BlobInfo
。
一般来说,正如 Skirmantas 指出的那样,将模型实例传递给 deferred 通常不是一个好主意。如果可能,请发送 key ,如果没有,请将实例序列化到 Protocol Buffer 并发送它们。
关于python - PicklingError : Can't pickle <class . ..> : it's not the same object as . .. 在 GAE 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8966685/
假设我有一个 A 类和一个派生自 A 的 B 类。我想 pickle/unpickle B 类的一个实例。A 和 B 都定义了 __getstate__/__setstate__ 方法(假设 A
似乎有两种方法可以将指标推向 Graphite /碳, 线路接收器 pickle 接收器 根据文档 http://graphite.readthedocs.org/en/1.0/feeding-car
Perforce命令行有一个特殊的开关-G,它使用python的“pickle”序列化格式可以使输出成为机器可读的。一般来说,实际上是这样吗? 例如,考虑p4 -G diff -duw3 的输出。
如何从 BytesIO 对象写入和读回 pickled 数据? 我尝试过: import io import cPickle as pickle s1 = "foo" bytes_io = io.By
我有两个文件: x.py class BF(object) def __init__(): . . def add(self,z): . . y.py from y
在 post昨天发帖,无意中发现改了__qualname__函数对 pickle 有意想不到的影响.通过运行更多测试,我发现在对函数进行 pickle 时,pickle不像我想的那样工作,改变 __q
为什么 pickle 重用现有的 Python 类“C”而不是从 pickle 字节重建类?有没有一种方法可以在没有副作用的情况下 pickle 和解 pickle ? 这是我的回复 session
我使用 mpi4py 将一些计算拆分到多个过程中。基本上我只是计算一些凸包的体积,这是我使用 tvtk 和 mayavi 创建的。 只有第一个过程导入这些库: ... if rank==0: f
我正在用 pygame 制作一个绘图程序,我想在其中为用户提供一个选项来保存程序的确切状态,然后在稍后重新加载它。在这一点上,我保存了我的全局字典的副本,然后遍历, pickle 每个对象。 pyga
所以,我有一个对象,里面有很多不可 pickle 的东西(pygame 事件、orderedDicts、时钟等),我需要将它保存到磁盘。 事情是,如果我可以让这个东西存储一个有进度的字符串(我只需要一
import pickle variety = ["sweet", "box", "cat"] shape = ["back","spear", "log"] pickleFile = open("
我有一个关于 gensim 的问题。我想知道在保存或加载模型(或多个模型)时是否建议或需要使用 pickle,因为我在 GitHub 上找到了可以使用的脚本。 mymodel = Doc2Vec(do
我正在使用 python3.6/。我使用 protocol=pickle.HIGHEST_PROTOCOL pickle 了我的文件 当我按如下方式加载时: with open('data.sav',
给定一个像这样的任意Pythonic对象: class ExampleObj(object): def __init__(self): self.a = 'a'
简介 我有一本具有以下格式的字典: dict_list = {'S0':[[list of int],[list of int]], 'S1':[[list of int],[list of int]
我想知道这个错误可能意味着什么: PicklingError: Can't pickle : attribute lookup __builtin__.function failed 我理解这与使用多
我对 python 变量持久性有点困惑,在我的代码中,我使用以下代码使模型参数在某些迭代期间持久化 with open('W_Hs_Hu_iter'+str(inx)+'.pickle', 'wb'
当对象通过其属性之一引用自身时,从带有插槽的类中挑选对象的正确方法是什么?这是一个简单的示例,使用我当前的实现,我不确定它是否 100% 正确: import weakref import pickl
我有数千个长 (8640) 整数列表元组。例如: type(l1) tuple len(l1) 2 l1[0][:10] [0, 31, 23, 0, 0, 0, 0, 0, 0, 0] l1[1][
我有一个对象 gui_project,它有一个属性 .namespace,这是一个命名空间字典。 (即从字符串到对象的字典。) (这在类似 IDE 的程序中使用,让用户在 Python shell 中
我是一名优秀的程序员,十分优秀!