我需要使用Google AppEngine設置一個cron作業,它將使用urllib2來執行託管在我的另一臺服務器上的網頁。Google AppEngine Python Cron作業urllib
我知道腳本正在執行(檢查日誌),但我的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()
任何人都可以看到有什麼不對嗎?
fwiw,你可能最好使用urlfetch API而不是urllib;你有更多的控制權,例如超時,urllib支持的設計真的是與現有的庫兼容,而不是直接在你的代碼中使用。 – geoffspear 2011-05-06 14:16:33
謝謝Wooble,我會確保我使用它:) – James 2011-05-06 14:19:14