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

2024-04-20 10:26:47 发布

您现在位置:Python中文网/ 问答频道 /正文

这篇文章是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部分显示为红色的“Failed”),并且它应该运行的任务队列永远不会在任务队列部分弹出。在

我不明白的是,如果我手动打开/update,我会看到下面的登录提示。克朗怎么能绕过这个?我如何调试正在发生的事情?在

GAE login prompt

谢谢你的帮助。在

编辑/跟踪@dlebech answer:在app.yaml中的相关url行中添加login: admin后,问题仍然存在。在本地(通过以管理员身份登录并访问浏览器中处理程序的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
    

Tags: comidhttpobjectyoutubegooglecodedecorator
1条回答
网友
1楼 · 发布于 2024-04-20 10:26:47

How is cron supposed to bypass that?

确保cron url配置为login: adminnotlogin: required。Cron作业会自动通过登录提示。有关详细信息,请参见the documentation。在

How can I debug what's going on?

由于cron作业是由对特定url的GET请求启动的,所以您应该能够通过对该url发出GET请求来调试该作业,并查看开发服务器犯了什么错误,或者查看GET请求的日志中有什么内容。在

相关问题 更多 >