class registerPage(webapp2.RequestHandler):
def post(self):
deviceID = cgi.escape(self.request.get('deviceID'))
PNID = cgi.escape(self.request.get('PNID'))
try:
user = RegisteredUser.get_or_insert(deviceID)
user.push_notification_ID = PNID
try:
user.put()
self.response.headers['Content-Type'] = "text/plain"
self.response.set_status(201)
logging.info("DeviceID = %s",newUser.key().name())
except Timeout:
logging.error("Timeout:%s unable to put user",deviceID)
except TransactionFailedError:
logging.error("TransactionFailedError:%s unable to put user",deviceID)
except InternalError:
logging.error("InternalError:%s unable to put user",deviceID)
except:
logging.error("%s unable to save Push Notification",deviceID)
self.response.headers['Content-Type'] = "text/plain"
self.response.set_status(204)
我不太明白为什么我在最外层的范围内获得异常,即调用get_or_insert时。交易成功了。我很确定它有效但我可以检索实体并看到新的实体已被添加。有人会知道发生了什么吗?