盖伊self.request.cookies返回空di

2024-10-04 03:28:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图重写CheckIsAdmin类中的CheckIsAdmin方法。所以我遵循了this的答案。但我总是在打印时得到空的结论self.request.cookies。在

在某些情况下,我得到了打印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)])

app.yaml的一部分看起来像

^{pr2}$

如果我的.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方法的开头,它就可以正常工作了。但它缺乏安全性。。在


Tags: thepyimportselfapireturncookierequest
1条回答
网友
1楼 · 发布于 2024-10-04 03:28:56

看起来他们删除了 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代码。在

相关问题 更多 >