Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python GAE self.request.cookies返回一个空的dict_Python_Google App Engine - Fatal编程技术网

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令牌来执行相同的操作。