GAE self.request.cookies返回一个空字典 [英] GAE self.request.cookies return an empty dict
问题描述
我试图覆盖 ApiCallHandler
类中存在的 CheckIsAdmin
方法。所以我遵循这个回答。但是我总是会打印空字典 self.request.cookies
。
在某些时候,打印 self.request.cookies
,但不会。我已经检查过我的服务器正在运行,并且我已经入侵了。
remote_api.py
看起来像
导入re
导入模型
from google.appengine.ext.remote_api导入处理程序
从google.appengine.ext import webapp
MY_SECRET_KEY ='foo@bar.com'#make up,在shell命令中使用相同的命令
class ApiCallHandler(handler.ApiCallHandler):
$ b $ def CheckIsAdmin(self):
'''
确定是否应根据传递的
auth cookie来授予管理员访问权限请求。
'''
$ b'''
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'头文件'str(self.request.headers)
如果在self.request.headers中匹配并匹配[0] == MY_SECRET_KEY \
和'X-Appcfg-Api-Version':
print'返回true'
返回True
app = webapp.WSGIApplication([('。*',ApiCallHandler)])
部分 app.yaml
看起来像
- url:/remoteapi.*
脚本:api.remote_api.app
在 api
文件夹内存在 .py
文件时,这是正确的。
当我试过这个命令时,
echofoo@bar.com| appcfg.py upload_data --email=some@example.org --passin --url = http:// localhost:8080 / remoteapi --num_threads = 4 --db_filename = bulkloader.csv
它显示无效参数 - passin
,如果我将 return True
在 CheckIsAdmin
方法的开头。但它缺乏安全性。
看起来他们删除了 - passin
现在完全依赖oauth。
https://code.google.com/p/googleappengine/wiki/SdkReleaseNotes#Version_1.9.24_-_July_20,_2015
- passin
是导致cookies被设置的标志。看起来您需要降级到1.9.24以下的sdk版本,或更改命令以使用oauth并删除自定义 ApiCallHandler
代码。
I'm trying to override CheckIsAdmin
method present in ApiCallHandler
class. So I followed this answer. But I always get empty dict on printing self.request.cookies
.
At some point I get the values on printing self.request.cookies
but not it won't. I have checked that my server is running and I'm already looged in.
remote_api.py
looks like
import re
import models
from google.appengine.ext.remote_api import handler
from google.appengine.ext import webapp
MY_SECRET_KEY = 'foo@bar.com' # 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)])
part of app.yaml
looks like
- url: /remoteapi.*
script: api.remote_api.app
This is correct where my .py
file exists inside api
folder..
When I'have tried this command,
echo "foo@bar.com" | appcfg.py upload_data --email=some@example.org --passin --url=http://localhost:8080/remoteapi --num_threads=4 --db_filename=bulkloader.csv
it shows invalid parameter --passin
and it works perfectly if I placed return True
at the start of CheckIsAdmin
method. But it lacks security..
It looks like they removed --passin
and now exclusively rely on oauth.
https://code.google.com/p/googleappengine/wiki/SdkReleaseNotes#Version_1.9.24_-_July_20,_2015
--passin
was the flag that caused cookies to get set. It looks like you will need to downgrade to an sdk version below 1.9.24 or change the command to use oauth and remove the custom ApiCallHandler
code.
这篇关于GAE self.request.cookies返回一个空字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!