2016-01-12 31 views
4

我試圖覆蓋CheckIsAdmin方法存在於ApiCallHandler類。所以我跟着this回答。但我總是在打印self.request.cookies上得到空字典。GAE self.request.cookies返回一個空字典

在某些時候,我得到了打印self.request.cookies的值,但它不會。我已經檢查了我的服務器運行的是,我在已經looged。

remote_api.py看起來像

import re 
import models 
from google.appengine.ext.remote_api import handler 
from google.appengine.ext import webapp 

MY_SECRET_KEY = '[email protected]' # make one up, use the same one in the shell command 


class ApiCallHandler(handler.ApiCallHandler): 

    def CheckIsAdmin(self): 
     ''' 
     Determine if admin access should be granted based on the 
     auth cookie passed with the request. 
     ''' 

     ''' 
     print 'App id ' + models.APPLICATION_ID 
     print 'on checkIsAdmin' 
     print 'request.cookies ' + str(self.request.cookies) 
     login_cookie = self.request.cookies.get('dev_appserver_login', '') 
     match = login_cookie.split(':') 
     print 'headers '+ str(self.request.headers) 
     if match and match[0] == MY_SECRET_KEY \ 
       and 'X-Appcfg-Api-Version' in self.request.headers: 
      print 'Going to return true' 
      return True 

app = webapp.WSGIApplication([('.*', ApiCallHandler)]) 

app.yaml部分看起來像

- url: /remoteapi.* 
    script: api.remote_api.app 

這是正確的地方我.py文件存在裏面有api文件夾..

當我試過這個命令時,

echo "[email protected]" | appcfg.py upload_data [email protected] --passin --url=http://localhost:8080/remoteapi --num_threads=4 --db_filename=bulkloader.csv 

它顯示無效的參數--passin和它完美的作品,如果我把return TrueCheckIsAdmin方法的開始。但它缺乏安全性..

+0

你知道演習,把它提煉成[mcve] –

+0

@JoshJ你在那裏嗎? –

+0

我不知道爲什麼你的cookies是空的,因爲你沒有發佈一個我可以用來重現你的問題的例子。我假設你在某個地方出了問題,但我只能猜測沒有代碼看。 –

回答

1

看起來他們刪除了--passin,現在完全依靠oauth。

https://code.google.com/p/googleappengine/wiki/SdkReleaseNotes#Version_1.9.24_-_July_20,_2015

--passin是導致cookie來獲得設置標誌。看起來您需要降級到低於1.9.24的sdk版本,或者更改命令以使用oauth並刪除自定義代碼ApiCallHandler

+0

增加了這個問題的賞金。沒有降級的方法嗎? –

+0

我最近沒有檢查過這個工具,所以我不知道如何解決它。我相信你可以創建一個服務帳戶並使用它的oauth令牌來執行相同的操作。 –