Google AppEngine Python Cron 作业 urllib
我需要使用 Google AppEngine 设置一个 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
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()
谁能看出这有什么问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
main()
应在util.run_wsgi_app(application)
之后结束。其余部分属于您的处理程序类。main()
should end afterutil.run_wsgi_app(application)
. The rest of that belongs in your handler class.我刚刚使用了 Google App Engine 根目录中的
main.py
,这似乎给了我更好的结果。除了德鲁提到的之外,还有一些问题。
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.