首页 文章

GAE Flask Oauth2Decorator 500错误

提问于
浏览
0

我正在尝试使用Oauth2Decorator来授权应用程序 - 在gae中作为flask应用程序运行 .

我为项目创建了client-id和client-secret,并在控制台中启用了API .

下面是添加装饰器的简单函数 . 因此,当用户访问该URL时,它应重定向到身份验证,但它显示500内部服务器错误 .

任何建议为什么500错误被抛出?

from oauth2client.contrib.appengine import OAuth2Decorator
decorator = OAuth2Decorator(
      client_id="abcde.apps.googleusercontent.com",
      client_secret="yyyyyy",
      scope="https://www.googleapis.com/auth/tasks")

@app.route("/")
@decorator.oauth_required
def welcome():
    try:
        #import pdb;pdb.set_trace()
        return "Hi Welcome"
    except Exception as e:
        print e

if __name__ == '__main__':
    app.run()

1 回答

  • 1

    oauth_required 装饰器只能用于装饰 webapp.RequestHandler 实例的方法,而不是任意方法 - 它实际上使用该实例 . 这可能会使它与Flask不兼容 .

    检查OAuth2Decorator.oauth_required source codemethod arg的doc字符串:

    def oauth_required(self, method):
        """Decorator that starts the OAuth 2.0 dance.
    
        Starts the OAuth dance for the logged in user if they haven't already
        granted access for this application.
    
        Args:
            method: callable, to be decorated method of a webapp.RequestHandler
                    instance.
        """
    

相关问题