开发者

Google AppEngine Python Cron job urllib

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
imp开发者_如何学运维ort 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 after util.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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜