本文介绍了AttributeError:“WSGIRequest”对象在OAuth2Decorator上没有属性“请求”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想使用装饰器,如文档中所述,但是我遇到了一个问题,即Google App Engine上的Django尝试访问Google API。一次又一次地得到相同的错误:

  AttributeError:'WSGIRequest'对象没有属性'request'

和StackTrace:

 内部服务器错误:/ 
追溯(最近的最后一次呼叫):
文件/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/ django-1.5 / django / core / handlers / base.py,第115行,get_response
response = callback(request,* callback_args,** callback_kwargs)
文件/ Users / johannes / GitHub / itzehoe / dependencies / oauth2client / appengine.py,第703行,check_oauth
self._create_flow(request_handler)
文件/Users/johannes/GitHub/itzehoe/dependencies/oauth2client/appengine.py,第734行,在_create_flow中
redirect_uri = request_handler.request.relative_url(
AttributeError:'WSGIRequest'对象没有属性'request'

和一些代码:

 来自google.appengine.api从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)


解决方案

OAuth2Decorator功能假设您在 webapp webapp2 <$ c中包装方法$ c> RequestHandler 子类,它不是设计nd与django意见合作。


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)
解决方案

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

这篇关于AttributeError:“WSGIRequest”对象在OAuth2Decorator上没有属性“请求”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 08:16