0
我在一個RequestHandler堅持這樣的實體,並且可以通過SDK控制檯驗證:GAE的Python類型錯誤的數據存儲篩選查詢
class Moment(db.Model):
user = db.IntegerProperty()
index = db.IntegerProperty()
編輯:我以前只包含部分類定義,並沒有表現出我是如何編寫模型的。下面是完整的例子:
class Moment(db.Model):
user = db.IntegerProperty()
index = db.IntegerProperty()
date = db.DateTimeProperty()
qx = db.FloatProperty()
qy = db.FloatProperty()
qz = db.FloatProperty()
qw = db.FloatProperty()
latitude = db.FloatProperty()
longitude = db.FloatProperty()
image = db.BlobProperty()
def __init__(self, obj):
super(Moment,self).__init__()
self.user = obj['user']
self.index = obj['index']
self.date = obj['date']
self.qx = obj['qx']
self.qy = obj['qy']
self.qz = obj['qz']
self.qw = obj['qw']
self.latitude = obj['latitude']
self.longitude = obj['longitude']
self.image = obj['image']
class UploadHandler(webapp2.RequestHandler):
def post(self):
obj = biplist.readPlistFromString(self.request.body)
Moment(obj).put()
當我嘗試過濾GET ...
class ServeHandler(webapp2.RequestHandler):
def get(self):
params = {}
params['user'] = int(self.request.get('user'))
params['index'] = int(self.request.get('index'))
q = Moment.all()
q.filter("user =", params['user'])
q.filter("index =", params['index'])
print q.get()
我得到如下:
ERROR 2012-11-04 06:56:04,846 webapp2.py:1553] __init__() got an unexpected keyword argument 'index'
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1536, in __call__
rv = self.handle_exception(request, response, e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1530, in __call__
rv = self.router.dispatch(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "<path>/main.py", line 51, in get
print q.get()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 2102, in get
return results.next()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 2314, in next
return self.__model_class.from_entity(self.__iterator.next())
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 1442, in from_entity
return cls(None, _from_entity=entity, **entity_values)
TypeError: __init__() got an unexpected keyword argument 'index'
INFO 2012-11-04 06:56:04,849 dev_appserver.py:3092] "GET /serve?user=0&index=0 HTTP/1.1" 500 -
但是,如果我這樣做print q.count()
,而不是print q.get()
我會得到1.似乎我正在根據文檔正確地做事,我嘗試了我發現的類似問題的建議,但無濟於事。
SDK v1.7.3
上述代碼確實對我有用。一些事情: - 使用'logging'而不是'print',嘗試記錄來自請求參數的值,您是否可以更改模型定義?比如從模型中的db.StingProperty到db.InteProProperty,現有的實體仍然有'string'而不是'int'? – aschmid00