Google AppEngine Python Cron作业urllib [英] Google AppEngine Python Cron job urllib

查看:103
本文介绍了Google AppEngine Python Cron作业urllib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Google AppEngine设置cron作业,这将使用urllib2执行托管在我的另一个服务器上的网页。



我知道

 #!/ 

usr / bin / env python
来自google.appengine.ext import webapp
来自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 b $ b urlStr =http://example.com/cron.php

request = urllib2.Request(urlStr)
try:
response = urllib2.urlopen请求)
logging.info(备份完成!)
除了URLError,e:
logging.error('出现错误%s',e.reason)


if __name__ =='__main__':
main()



<

>应该在 util.run_wsgi_app(application)后结束。其余的属于你的处理程序类。


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 after util.run_wsgi_app(application). The rest of that belongs in your handler class.

这篇关于Google AppEngine Python Cron作业urllib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆