【问题标题】:AttributeError: 'WSGIRequest' object has no attribute 'request' on OAuth2DecoratorAttributeError:“WSGIRequest”对象在 OAuth2Decorator 上没有“请求”属性
【发布时间】:2014-02-21 19:16:28
【问题描述】:

我在 Google App Engine 上使用 Django 尝试访问 Google API 时遇到了问题。

我想使用文档中描述的装饰器,但我一遍又一遍地遇到相同的错误:

AttributeError: 'WSGIRequest' object has no attribute 'request'

还有 StackTrace:

Internal Server Error: /
Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/Users/johannes/GitHub/itzehoe/dependencies/oauth2client/appengine.py", line 703, in check_oauth
    self._create_flow(request_handler)
  File "/Users/johannes/GitHub/itzehoe/dependencies/oauth2client/appengine.py", line 734, in _create_flow
    redirect_uri = request_handler.request.relative_url(
AttributeError: 'WSGIRequest' object has no attribute 'request'

还有一些代码:

from google.appengine.api import users
from oauth2client.appengine import OAuth2DecoratorFromClientSecrets

from django.shortcuts import render
from django.conf import settings

decorator = OAuth2DecoratorFromClientSecrets(settings.GOOGLE_CLIENT_SECRETS,
                                             'https://www.googleapis.com/auth/admin.directory.group')


@decorator.oauth_required
def index(request):
    context = {}
    return render(request, 'index.html', context)

【问题讨论】:

  • 好吧,你显然做错了什么,但我们不能告诉你是什么,因为你没有发布任何代码。
  • @DanielRoseman 更好?

标签: django google-app-engine google-api google-api-python-client python-decorators


【解决方案1】:

OAuth2Decorator 功能假定您将方法包装在 webapp 或 webapp2 RequestHandler 子类中,它并非设计用于 django 视图。

【讨论】:

猜你喜欢
  • 2022-01-21
  • 2018-09-06
  • 1970-01-01
  • 2011-03-15
  • 2021-07-04
  • 2021-12-13
  • 1970-01-01
  • 2019-10-20
  • 2016-02-02
相关资源
最近更新 更多