<< Big update below implies it’s simply a logging issue >>
I’m trying to get app engine setup with python and having some problem that I suspect is some simple step I’ve missed. My app.yaml says this:
application: something #name here is the one I used to register i.e. something.appspot.com
version: 1
runtime: python
api_version: 1
handlers:
- url: .*
script: myapp.py
and my myapp.py says this:
import cgi
import Utils
import Sample
import logging
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
class MainPage(webapp.RequestHandler):
def get(self):
self.response.out.write('<html><body>')
self.response.out.write('Welcome to my server! Why is this not working?')
self.response.out.write('</body></html>')
def main():
application = webapp.WSGIApplication([('/', MainPage),
('/Sample', Sample.HttpRequestHandler)],
debug=True)
run_wsgi_app(application)
if __name__ == "__main__":
main()
When I run this on localhost, I get my html “Welcome” message when passing in / but when I pass in /Sample I don’t get any where. Also, I can’t seem to log messages. I call logging.debug() and nothing shows on the log console. Any ideas? Here is my Sample.py. Sorry about the strange tabbing. Copy paste didn’t line them up and editing it by hand didn’t seem to correct it.
class HttpRequestHandler(webapp.RequestHandler):
def get(self):
Utils.log("Sample handler called")
try:
if HttpRequestHandler.requestIsValid(self):
intParam = int(self.request.get('param1'))
floatParam = float(self.request.get('param1'))
stringParam = self.request.get('param1')
Utils.log("params: " + str(intParam) + " " + str(floatParam) + " " + stringParam)
if intParam == 1:
self.response.set_status(200, message="Success")
else:
self.response.set_status(400, message="Error processing sample command")
else:
raise StandardError
except Exception, e:
logging.debug("Exception: %s" % (e))
self.response.set_status(400, message="Error processing sample command")
def requestIsValid(self):
if self.request.get('param1') != "" and \
self.request.get('param2') != "" and \
self.request.get('param3') != "":
return True
else:
return False
So I know this is totally lame, but since I couldn’t see any log messages, I threw in a bunch of “raise StandardError” calls just to see what would throw exception output to my browser window when I try to invoke my Sample message. What I found was that the server is calling into the Sample handler just fine it seems, even checking the int param is right.
I think the problem is that I just can’t see my log messages! Any idea why they aren’t showing up? I call logging.debug() through those Util.log() calls. Is there some flag or something suppressing my output from showing in the log console?
I discovered that indeed it was a logging issue (everything underneath was working just fine). I use Google App Engine Launcher, so here’s what I had to do with the settings to get it to work:
Go into Edit -> Application Settings
under Extra Flags add the flag -d
I also selected to clear the datastore at launch in my settings, but I don’t think this impacts the logs.