Google App Engine(Python SDK) - 如何捕获数据库异常

时间:2014-09-20 16:10:35

标签: python google-app-engine

我正在使用带有Python的Google App Engine并遇到如下错误:

raise BadValueError('Property %s is not multi-line' % self.name)
BadValueError: Property title is not multi-line
ERROR    2014-09-20 16:01:23,969 wsgi.py:278] 
Traceback (most recent call last):

我导入了db模块:from google.appengine.ext import db

我试图默默地(现在)用这样的代码捕获错误:

try:
    r.put()
except db.Error:
    pass

然而,错误继续打破程序执行。我究竟做错了什么? (或不做?)

...谢谢

以下是完整的追溯:

Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 547, 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-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "/Users/me/myapp/myapp.py", line 191, in get
    date_last_modified = date_last_modified)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 970, in __init__
    prop.__set__(self, value)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 614, in __set__
    value = self.validate(value)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 2847, in validate
    raise BadValueError('Property %s is not multi-line' % self.name)
BadValueError: Property column_series is not multi-line

1 个答案:

答案 0 :(得分:0)

设置属性时引发异常;您可以在回溯中的代码中看到行的最后一部分:

  File "/Users/me/myapp/myapp.py", line 191, in get
    date_last_modified = date_last_modified)

您正在创建或更新那里的实例,以及应该捕获异常的地方,而不是在调用r.put()时。