这篇文章是如何在 GAE 任务队列中执行需要 OAuth 的操作?. 正如 bossylobster 在这篇文章中所建议的那样,我确实尝试user_id
在我的脚本中硬编码,但 cron 任务总是失败:
我可以看到它在日志中被触发......
2013-05-31 14:20:00.879 /update 302 5ms 0kb AppEngine-Google; (+http://code.google.com/appengine) 0.1.0.1 - - [31/May/2013:11:20:00 -0700] "GET /update HTTP/1.1" 302 385 - "AppEngine-Google; (+http://code.google.com/appengine)" "myapp.appspot.com" ms=6 cpu_ms=0 cpm_usd=0.000043 queue_name=__cron task_name=... app_engine_release=1.8.0 instance=...
- ...但是,它总是失败(在 AppEngine 的Cron Jobs部分中显示为红色的“Failed” ),并且它应该运行的任务队列永远不会在Task Queues部分中弹出。
我不明白的是,如果我/update
手动打开,我会在下面看到登录提示。cron 应该如何绕过它?我怎样才能调试发生了什么?
谢谢您的帮助。
编辑/跟进@dlebech答案:login: admin
在url
. app.yaml
在本地(通过以管理员身份登录并在浏览器中访问处理程序的 URL,如Securing URLs for Cron中所述)一切正常,但是一旦我部署,我的应用程序永远不会通过 OAuth2 装饰器:
用一些调试
print
语句......import webapp2 ... YOUTUBE_RW_SCOPE = "https://www.googleapis.com/auth/youtube" YOUTUBE_API_SERVICE_NAME = "youtube" YOUTUBE_API_VERSION = "v3" print "Building youtube object" print "Built youtube object" youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION) print "Building decorator object" decorator = OAuth2DecoratorFromClientSecrets(CLIENT_SECRETS, YOUTUBE_RW_SCOPE) print "Built decorator object" ... class FetchHandlerPage(webapp2.RequestHandler): print "Entering FetchHandlerPage" @decorator.oauth_required def get(self): print "Entering FetchHandlerPage:get" gae_user_id = USER_ID query_string = urlencode({'user_id': gae_user_id}) taskqueue.add(url='/fetchworker?' + query_string, method='GET')
...这是我在 GAE 日志中部署后看到的内容(日志在最后一行停止,接下来什么也没有发生):
2013-05-31 16:12:02.765 /fetch 302 1746ms 0kb AppEngine-Google; (+http://code.google.com/appengine) 0.1.0.1 - - [31/May/2013:13:12:02 -0700] "GET /fetch HTTP/1.1" 302 385 - "AppEngine-Google; (+http://code.google.com/appengine)" "myapp.appspot.com" ms=1747 cpu_ms=844 cpm_usd=0.000070 queue_name=__cron task_name=... loading_request=1 app_engine_release=1.8.0 instance=... I 2013-05-31 16:12:02.444 URL being requested: https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest?userIp=0.1.0.1 E 2013-05-31 16:12:02.764 Building youtube object E 2013-05-31 16:12:02.764 Built youtube object E 2013-05-31 16:12:02.764 Building decorator object E 2013-05-31 16:12:02.764 Built decorator object E 2013-05-31 16:12:02.764 End static variables E 2013-05-31 16:12:02.764 Entering FetchHandlerPage I 2013-05-31 16:12:02.765 This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This requ