2

我遇到了在Google App Engine上使用Django試圖訪問Google API的問題。AttributeError:'WSGIRequest'對象在OAuth2Decorator上沒有任何屬性'請求'

我想使用的裝飾,如文檔所描述的,但我在得到同樣的錯誤一遍又一遍:

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

而且堆棧跟蹤:

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) 
+0

那麼,你已經明確地做了錯誤的事情,但我們不能告訴你它是什麼,因爲*你沒有發佈任何代碼*。 –

+0

@DanielRoseman更好? – codingjoe

回答

3

OAuth2Decorator功能假設您將方法包裝在webapp或中RequestHandler子類,它的設計目的不是用於處理django視圖。

+0

所以我需要使用'Flows'?在GAE上如何在Django中使用Google API有沒有很好的例子? – codingjoe

+0

我不是django開發人員,因此無法保證其質量,但在適合的回購中有一個示例應用程序:https://code.google.com/p/google-api-python-client/source/瀏覽/#汞柱%2Fsamples%2Fdjango_sample – Greg

相關問題