gpt4 book ai didi

python - PicklingError : Can't pickle : it's not the same object as . .. 在 GAE 中

转载 作者:行者123 更新时间:2023-12-01 06:03:58 26 4
gpt4 key购买 nike

我从我的 GAE Python 应用程序中的这行代码中收到 PicklingError:

deferred.defer(email_voters_begin, ekey, voter_list)

这三个参数是:

  • email_voters_begin -- 一个 Python 函数,例如位于 0x1035d4488 的函数 email_voters_begin
  • ekey -- 我定义的实体的 key ,例如,打印为 agdvcGF2b3Rlcg4LEghFbGVjdGlvbhgCDA
  • voter_list -- 我定义的对象列表,例如,[models.Voter 对象位于 0x103d3d310, ... ]

当此行作为我的测试的一部分执行时(使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com