Google AppEngine Python Cron job urllib

I need to configure cron to work using Google AppEngine, which will use urllib2 to execute a webpage hosted on my other server.

I know that a script is running (logs checked), but my log inside my python script is never output.

#!/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 something wrong with this?

+1
source share
2 answers

main()should end after util.run_wsgi_app(application). The rest belongs to the handler class.

+2
source

I just used the main.pyGoogle App Engine from the root, and this seems to give me a better result.

There were a few problems, besides what Drew was talking about.

0
source

All Articles