ndb在StringProperty上获取密钥验证错误

时间:2014-02-20 21:29:47

标签: python google-app-engine app-engine-ndb

我有一个奇怪的消息错误。

我有一个名为StringProperty checksum的模型,但是当我尝试保存到它时,我收到一个验证错误,声称预计会有一个Key值。

编辑:为避免潜在问题,我将id属性重命名为gdid,因为它现在已显示,并且错误仍然存​​在。

class gd_file(base_class):
    """Google Drive File Reference"""
    gdid = ndb.StringProperty()
    #creation_date = ndb.DateTimeProperty()
    #modification_date = ndb.DateTimeProperty()
    name = ndb.StringProperty()
    checksum = ndb.StringProperty()
    size = ndb.IntegerProperty()
    office = ndb.KeyProperty()
    parents = ndb.KeyProperty()

示例代码:

            logging.info('GD_FILE:')
            for p in gd_file._properties:
                logging.info( getattr(gd_file,p))

            logging.info('m:')
            logging.info(type(m))
            logging.info(m)

            fd = gd_file(
                parents = parents_list,
                owners = gd['ownerNames'],
                last_changed_by = gd['lastModifyingUserName'],
                creation_date = datetime.datetime.strptime(cdate, '%Y-%m-%d %H:%M:%S.%f'),
                modification_date = datetime.datetime.strptime(mdate, '%Y-%m-%d %H:%M:%S.%f'),
                gdid = gd['id'],
                name = result['name'],
                size = result['size'],
                type = gd['mimeType'],
                checksum = m
            )

我的代码中的第231行是我将checksum = m置于上面的位置。

记录包括错误:

INFO     2014-02-20 21:20:09,042 proterrahandler.py:213] GD_FILE:

INFO     2014-02-20 21:20:09,042 proterrahandler.py:215] KeyProperty('parents')

INFO     2014-02-20 21:20:09,042 proterrahandler.py:215] StringProperty('checksum')

INFO     2014-02-20 21:20:09,042 proterrahandler.py:215] StringProperty('owners', repeated=True)

INFO     2014-02-20 21:20:09,042 proterrahandler.py:215] DateTimeProperty('creation_date', auto_now_add=True)

INFO     2014-02-20 21:20:09,042 proterrahandler.py:215] StringProperty('type')

INFO     2014-02-20 21:20:09,042 proterrahandler.py:215] StringProperty('last_changed_by')

INFO     2014-02-20 21:20:09,042 proterrahandler.py:215] StringProperty('name')

INFO     2014-02-20 21:20:09,042 proterrahandler.py:215] IntegerProperty('size')

INFO     2014-02-20 21:20:09,042 proterrahandler.py:215] DateTimeProperty('modification_date', auto_now=True)

INFO     2014-02-20 21:20:09,042 proterrahandler.py:215] KeyProperty('cid')

INFO     2014-02-20 21:20:09,042 proterrahandler.py:215] KeyProperty('office')

INFO     2014-02-20 21:20:09,042 proterrahandler.py:215] StringProperty('id')

INFO     2014-02-20 21:20:09,042 proterrahandler.py:217] m:

INFO     2014-02-20 21:20:09,042 proterrahandler.py:218] <type 'str'>

INFO     2014-02-20 21:20:09,042 proterrahandler.py:219] 019f8998e5896bb34ecdbb0803343486

ERROR    2014-02-20 21:20:09,046 webapp2.py:1552] Expected Key, got [u'0B2PeVr8B69LER2ZGWVNjM29TSTQ']

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:\Users\Tiago\Google Drive\Development\gae\cert-id-tinkerbox\proterrahandler.py", line 89, in post

    files = self.handle_upload()

  File "C:\Users\Tiago\Google Drive\Development\gae\cert-id-tinkerbox\proterrahandler.py", line 231, in handle_upload

    checksum = m

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 2852, in __init__

    self._set_attributes(kwds)

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 3587, in _set_attributes

    setattr(self, name, value)

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 3605, in __setattr__

    return super(Expando, self).__setattr__(name, value)

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 1343, in __set__

    self._set_value(entity, value)

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 1088, in _set_value

    value = self._do_validate(value)

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 1035, in _do_validate

    value = self._call_shallow_validation(value)

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 1227, in _call_shallow_validation

    return call(value)

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 1274, in call

    newvalue = method(self, value)

  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 1927, in _validate

    raise datastore_errors.BadValueError('Expected Key, got %r' % (value,))

BadValueError: Expected Key, got [u'0B2PeVr8B69LER2ZGWVNjM29TSTQ']

INFO     2014-02-20 18:20:09,193 module.py:612] default: "POST /app/proterra/checklist/import HTTP/1.1" 500 3357

我对这一点感到有点难过,我不知道Key错误发生在哪里。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您不能拥有名为id

的属性

它是一个提供给构造函数的参数,用于创建具有提供的id的Key。

阅读ndb.Model文档https://developers.google.com/appengine/docs/python/ndb/modelclass#Constructor