App Engine: TypeError in handlers.py
I get a problem in a form handler in app engine (Python). Basically when I post the form to the handler I get the following traceback:
INFO 2011-02-07 14:06:59,364 dev_appserver.py:3317] "GET /favicon.ico HTTP/1.1" 404 - Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/wsgiref/handlers.py", line 92, in run self.result = application(self.environ, self.start_response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 531, in __call__ handler.handle_exception(e, self.__debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 394, in handle_exception self.error(500) TypeError: 'bool' object is not callable
INFO 2011-02-07 14:07:01,986 dev_appserver.py:3317] "POST /newevent HTTP/1.1" 500 -`
On the browser I get the message 'A server error occurred. Please contact the administrator'. As you can see, the error happens before the POST command, and doesn't seem to stem from any of my handler code. Here's the handler class for that form (post_secure is a method called by the post method in the parent class):
class SaveEvent(BaseHandler):
def post_secure(self):
userinfo = db.GqlQuery("SELECT * FROM User WHERE fbid = :1", self.user['uid'])[0]
newevent = Event(parent=userinfo)
self.error = False
self.template_values = {}
if (self.request.get('eventname') == ""):
self.template_values['eventnameerror'] = True
self.error = True
else:
newevent.eventname = self.request.get('eventname')
if (self.request.get('venuename') == ""):
self.template_values['venuenameerror'] = True
self.error = True
else:
newevent.venuename = self.request.get('venuename')
if (re.match("[0-9]+.[0-9][0-9]", self.request.get('eventprice')) == None):
self.template_values['eventpriceerror'] = True
self.error = True
else:
newevent.price_pence = int(float(self.request.get('eventprice')) * 100)
if (re.match("[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]", self.request.get('eventdate')) == None):
self.template_values['eventdateerror'] = True
self.error = True
else:
day = re.split("/", self.request.get('eventdate'))[0]
month = re.split("/", self.request.get('eventdate'))[1]
year = re.split("/", self.request.get('eventdate'))[2]
if (re.match("[0-2][0-9]:[0-5][0-9]", self.request.get('eventtime')) == None):
self.template_values['eventtimeerror'] = True
self.error = True
else:
hours = re.split(":", self.request.get('eventtime'))[0]
minutes = re.split(":", self.request.get('eventtime'))[1]
try:
newevent.date = datetime.datetime(year, month, day, hours, minutes, 0, 0)
except ValueError:
self.template_values['eventdatetimeerror'] = True
self.error = True
if (newevent.date < datetime.datetime.now()):
self.template_values['eventdateerror2'] = True
self.error = True
if (self.request.get('eventlink') == ""):
self.template_values['eventlinkerror'] = True
self.error = True
if (self.error == True):
self.template_values['eventname'] = self.request.get('eventname')
self.template_values['venuename'] = self.request.get('venuename')
self.template_values['eventprice'] = self.request.get('eventprice')
self.template_values['eventdate'] = self.request.get('eventdate')
self.template_values['eventtime'] = self.request.get('eventtime')
self.template_values['eventlink'] = self.request.get('eventlink')
self.tpl('addevent.html', self.template_values)
newevent.put()
self.template_values = {
'newevent' : newevent
}
self.tpl('eventadded.html', self.template_values)
The RequestHandler
class has a method named error
error(code)
A shortcut method for handlers to use to return an error response. Clears the response output stream and sets the HTTP error code to code. Equivalent to calling self.response.clear() and self.response.set_status(code).
Your POST handler above overwrites that method with a boolean value, and then when the framework attempts to call self.error(500)
it throws an exception because the value of self.error
is no longer a callable.
Use a different member variable name than error
to prevent this.