Python 无法通过它读取AppEngine ndb模型';身份证

Python 无法通过它读取AppEngine ndb模型';身份证,python,google-app-engine,Python,Google App Engine,我要插入以下代码,然后按键读回一个实体。然而,我总是一无所获。我可以发誓这是我以前在AppEngine的旧版本中所做的 guid = uuid.uuid1().hex a = User(id=guid) a.email = "a" a.username = "a" a.put() logging.info("a.key: %s", a.key) theKey = ndb.Key(User, guid) entity1 = t

我要插入以下代码,然后按键读回一个实体。然而,我总是一无所获。我可以发誓这是我以前在AppEngine的旧版本中所做的

    guid = uuid.uuid1().hex

    a = User(id=guid)
    a.email = "a"
    a.username = "a"
    a.put()

    logging.info("a.key: %s", a.key)

    theKey = ndb.Key(User, guid)

    entity1 = theKey.get()          #doesnt work
    entity2 = User.get_by_id(guid)  #doesnt work

    logging.info("guid: %s", guid)
    logging.info("key: %s", keyValue)
    logging.info("entities: %s %s" % (entity1, entity2))

您正在记录尚未定义的keyValue。解决了这个问题,并定义了一个带有电子邮件和用户名属性的用户模型,代码运行良好,在这两种情况下都返回实体。这是你的实际代码吗?@Greg-你说得对,我刚刚检查了我的模型类,我有:id=ndb.StringProperty()-它不应该在那里…现在一切都正常了…非常尴尬:-/
guid
必须是字符串
str(guid)