Python GAE self.request.cookies返回一个空的dict
我正在尝试重写Python GAE self.request.cookies返回一个空的dict,python,google-app-engine,Python,Google App Engine,我正在尝试重写ApiCallHandler类中存在的CheckIsAdmin方法。所以我按照答案做了。但我总是在打印self.request.cookies时收到空的dict 在某个时刻,我在打印self.request.cookies时得到了值,但它不会。我已经检查了我的服务器是否正在运行,并且我已经失血过多 remote_api.py看起来像 import re import models from google.appengine.ext.remote_api import handler
ApiCallHandler
类中存在的CheckIsAdmin
方法。所以我按照答案做了。但我总是在打印self.request.cookies
时收到空的dict
在某个时刻,我在打印self.request.cookies时得到了值,但它不会。我已经检查了我的服务器是否正在运行,并且我已经失血过多
remote_api.py
看起来像
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)])
- url: /remoteapi.*
script: api.remote_api.app
app.yaml
的一部分看起来像
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)])
- url: /remoteapi.*
script: api.remote_api.app
如果我的.py
文件存在于api
文件夹中,则这是正确的
当我试过这个命令的时候
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
它显示无效的参数--passin
,如果我将return True
放在CheckIsAdmin
方法的开头,它就可以正常工作。但它缺乏安全性。看起来他们删除了--passin
,现在完全依赖oauth
--passin
是导致设置cookie的标志。看起来您需要降级到低于1.9.24的sdk版本,或者更改命令以使用oauth并删除自定义的ApiCallHandler
代码。您知道这个练习,将其提取到一个我不知道为什么您的cookie是空的,因为您没有发布一个我可以用来重新创建问题的示例。我想你哪里出了什么问题,但是我只能在没有代码的情况下猜测。我的朋友告诉我,只有当浏览器打开时,我们才能获得cookies的值。我是否需要浏览localhost:8080/remoteapi
链接?通过appcfg.py upload\u data
发送登录用户名和密码应该足以生成cookie.ya,它显示了无法识别的参数--passin
为这个问题添加了悬赏。没有降级的办法吗?我最近没有复习过这个工具,所以我不知道如何避开它。我相信您可以创建一个服务帐户,并使用它的oauth令牌来执行相同的操作。