Google App Engine Data store issue: Getting TypeError: Cannot set non-property when trying to insert into DataSTore

Google App Engine Data store issue: Getting TypeError: Cannot set non-property when trying to insert into DataSTore

模型定义

class SeqNumbers(ndb.Model):
"""APNS Server -- SeqNumbers object that stores sequence number of stored messages between two devices"""
  SeqNumberStart = ndb.IntegerProperty(required=True)
  SeqNumberEnd = ndb.IntegerProperty(required=True)
  Sourcein = ndb.StringProperty
  Destin = ndb.StringProperty

要添加到数据存储的代码。这导致 TypeError:无法设置非 属性 Sourcein(post 末尾的完整错误)

如果能帮助理解正在发生的事情,我们将不胜感激。

data ={}
data['SeqNumberStart']=0
data['SeqNumberEnd']=0
data['key']=seqKey
data['Sourcein']='user_IOT'
data['Destin']='user_SmartHome'
SeqNumbers(**data).put()

GAE 日志中的完整错误

E 02:08:17.725 Encountered unexpected error from ProtoRPC method implementation: TypeError (Cannot set non-property Sourcein)
  Traceback (most recent call last):
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0/protorpc/wsgi/service.py", line 181, in protorpc_service_app
      response = method(instance, request)
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/endpoints-1.0/endpoints/api_config.py", line 1332, in invoke_remote
      return remote_method(service_instance, request)
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0/protorpc/remote.py", line 414, in invoke_remote_method
      response = method(service_instance, request)
    File "/base/data/home/apps/s~chatimegae/v1.388953439373110592/apns_server.py", line 588, in sendMsg
      SeqNumbers(**data).put()
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 2942, in __init__
      self._set_attributes(kwds)
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 2987, in _set_attributes
      raise TypeError('Cannot set non-property %s' % name)
  TypeError: Cannot set non-property Sourcein

您需要初始化 Sourcein 和 Destin 的属性。只是把括号放在最后:

Sourcein = ndb.StringProperty()
Destin = ndb.StringProperty()