如何在GAE cron作业中执行OAuth操作?

前端之家收集整理的这篇文章主要介绍了如何在GAE cron作业中执行OAuth操作?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

这篇文章How to do OAuth-requiring operations in a GAE Task Queue?的后续内容.正如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部分显示为红色“失败”),它应该运行的任务队列永远不会弹出任务队列部分.

我不明白的是,如果我手动打开/更新,我在下面有登录提示. cron如何绕过那个?我该如何调试正在进行的操作?

谢谢您的帮助.

对@dlebech进行编辑/跟进回答:在app.yaml中添加登录后,问题仍然存在:admin行到相关网址.在本地(通过以管理员身份登录并访问Securing URLs for Cron中提到的浏览器中处理程序的URL)一切顺利,但是一旦部署,我的应用程序永远不会超过OAuth2装饰器:

>使用一些调试打印语句……

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
最佳答案

How is cron supposed to bypass that?

确保cron url配置了login:admin而不是login:required. Cron作业“自动通过登录提示”.有关更多信息,请参见the documentation.

How can I debug what’s going on?

由于cron作业是通过对特定URL的GET请求启动的,因此您应该能够通过向该URL发出GET请求来调试作业,并查看开发服务器发生的错误或查看日志中的内容. GET请求.

原文链接:https://www.f2er.com/python/439548.html

猜你在找的Python相关文章