修复过去5小时的BadKeyError错误。我想知道是否有人
你能帮我弄清楚。导致错误的应用程序部分
是处理用户投票的控制器。演员id是
用户和对象的密钥\u id是正在访问的对象的密钥
我一直在通过隐藏和还原一些代码来测试这个应用程序,我
正在创建实体(第二个块)。什么不起作用
我添加了控制器代码、模型代码和
日志页中的错误。
# Controller Code
class ActivityHandler(FacebookEnabled):
def get(self):
# i.e. fbid / headline id / upvote. This works
actor_id = self.request.get('actor_id')
object_id = self.request.get('object_id')
# creating actor and object from keys (actor_id and object_id).
# This works.
actor = models.Person.get(actor_id)
object = models.Headline.get(object_id)
logging.info("Actor " + str(actor) +": " + str(actor.name) +
" object " + str(object) + ": " + str(object.title))
# THIS IS WHAT SEEMS TO RAISE AN EXCEPTION
activity = models.Activity(actor, object, action='upvote')
activity.put()
# Model Code
class Activity(polymodel.PolyModel):
# User causing the action i.e. a person
actor = db.ReferenceProperty(Person, required=True,
collection_name='actors')
# The object being the subject of the action i.e. headline
object = db.ReferenceProperty(Headline, required=True,
collection_name='objects')
# The action being made
action = db.StringProperty(required=True, choices=['upvote','downvote'],
default='upvote')
回溯
Name must be string type, not Headline
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/
ext/webapp/__init__.py", line 511, in __call__
handler.get(*groups)
File "/base/data/home/apps/libnentest/2.343063076026692316/main.py",
line 125, in get
activity = models.Activity(actor, object, action='upvote')
File "/base/python_runtime/python_lib/versions/1/google/appengine/
ext/db/__init__.py", line 726, in __init__
key_name.__class__.__name__)
BadKeyError: Name must be string type, not Headline