gpt4 book ai didi

python - ProtocolBuffers 解码错误 : truncated when using ndb. key

转载 作者:行者123 更新时间:2023-11-30 23:32:08 26 4
gpt4 key购买 nike

我有这段代码,它在升级 GAE Python NDB 之前可以工作:

class MyHandler(webapp2.RequestHandler):
def get(self,urlString):
resume = ndb.Key(urlsafe=urlString).get()

现在,我遇到了这个错误:

Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__
return handler.dispatch()
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "C:\xampp\htdocs\mapjobs\main.py", line 127, in get
resume_key = ndb.Key(urlsafe=urlString)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\key.py", line 212, in __new__
self.__reference = _ConstructReference(cls, **kwargs)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\utils.py", line 136, in positional_wrapper
return wrapped(*args, **kwds)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\key.py", line 642, in _ConstructReference
reference = _ReferenceFromSerialized(serialized)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\key.py", line 774, in _ReferenceFromSerialized
return entity_pb.Reference(serialized)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\datastore\entity_pb.py", line 1791, in __init__
if contents is not None: self.MergeFromString(contents)
File "C:\Program Files (x86)\Google\google_appengine\google\net\proto\ProtocolBuffer.py", line 84, in MergeFromString
self.MergePartialFromString(s)
File "C:\Program Files (x86)\Google\google_appengine\google\net\proto\ProtocolBuffer.py", line 98, in MergePartialFromString
self.TryMerge(d)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\datastore\entity_pb.py", line 1920, in TryMerge
d.skipData(tt)
File "C:\Program Files (x86)\Google\google_appengine\google\net\proto\ProtocolBuffer.py", line 524, in skipData
self.skip(4)
File "C:\Program Files (x86)\Google\google_appengine\google\net\proto\ProtocolBuffer.py", line 499, in skip
if self.idx + n > self.limit: raise ProtocolBufferDecodeError, "truncated"
ProtocolBufferDecodeError: truncated

亮点可能是:

File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "C:\xampp\htdocs\mapjobs\main.py", line 127, in get
resume_key = ndb.Key(urlsafe=urlString)

出了什么问题?

最佳答案

我的猜测是,您通过 Url 参数接收作为 url 安全字符串的 key ,由于浏览器中的最大 Url 长度限制,该参数会被截断。实际上,浏览器将 URL 长度限制为最大 2000 个字符。看这个问题:What is the maximum length of a URL in different browsers?

如果您的 key 包含(多个)父 key ,则可能会超过 2000 个字符。是这样吗?请在创建和接收时检查 urlsafe 编码 key 的长度。

如果是这种情况,那么解决方法是仅使用实体(或父键的情况下的实体)的 ID 并手动构造键。

关于python - ProtocolBuffers 解码错误 : truncated when using ndb. key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19534222/

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