I'm in need of setting up a cron job using Google AppEngine which will use urllib2 to execute a web page hosted on another server of mine.
I know that the script is executing (checked the logs) but my logging inside my python script never seems to be outputted.
#!/usr/bin/env python
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
import logging
import urllib
import urllib2
class MainHandler(webapp.RequestHandler):
def get(self):
logging.info('Starting backups.')
def main():
application = webapp.WSGIApplication([('/', MainHandler)],
debug=True)
util.run_wsgi_app(application)
urlStr = "http://example.com/cron.php"
request = urllib2.Request(urlStr)
try:
response = urllib2.urlopen(request)
logging.info("Backup complete!")
except URLError, e:
logging.error('There was an error %s', e.reason)
if __name__ == '__main__':
main()
Can anyone see anything wrong with this?
main()
should end afterutil.run_wsgi_app(application)
. The rest of that belongs in your handler class.I just used
main.py
from the Google App Engine root and then this seems to give me a better result.There was a few problems other than what Drew mentioned too.