Google AppEngine Python Cron作业URL库
我需要使用GoogleAppengine设置一个cron作业,它将使用urllib2执行托管在我的另一台服务器上的网页 我知道脚本正在执行(检查了日志),但我在python脚本中的日志似乎从未输出Google AppEngine Python Cron作业URL库,python,google-app-engine,cron,Python,Google App Engine,Cron,我需要使用GoogleAppengine设置一个cron作业,它将使用urllib2执行托管在我的另一台服务器上的网页 我知道脚本正在执行(检查了日志),但我在python脚本中的日志似乎从未输出 #!/usr/bin/env python from google.appengine.ext import webapp from google.appengine.ext.webapp import util import logging import urllib import urllib2
#!/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()
有人看到这有什么问题吗?
main()
应该在util.run\u wsgi\u app(application)
之后结束。其余部分属于处理程序类。我刚刚使用了Google App Engine根目录中的main.py
,然后这似乎给了我更好的结果
除了Drew提到的问题之外,还有一些问题。输出还是记录?您没有向HTTP响应发出任何消息。在处理程序中使用self.response.out.write(msg)来输出某物。fwiw,您最好显式使用urlfetch API而不是urllib;你有更多的控制权,例如超时,urllib支持实际上是为了与现有库兼容而设计的,而不是直接在你的代码中使用。谢谢Wooble,我会确保我使用它:)你能具体说明其他问题吗,这样其他遇到同样问题的人会发现你的问题很有帮助吗?