Frage

I ran into an issue using Django on Google App Engine trying to access Google API.

I want to use the decorator, as described in the docs, but I get the same error over and over again:

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

And the 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'

And some code:

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)
War es hilfreich?

Lösung

The OAuth2Decorator functionality assumes you're wrapping methods in a webapp or webapp2 RequestHandler subclass, it's not designed to work with django views.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top