Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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 ndb查询在测试中本地工作,但在部署中不工作_Python_Google App Engine_App Engine Ndb - Fatal编程技术网

Python ndb查询在测试中本地工作,但在部署中不工作

Python ndb查询在测试中本地工作,但在部署中不工作,python,google-app-engine,app-engine-ndb,Python,Google App Engine,App Engine Ndb,我有一个ndb查询,它可以使用Google App Engine Launcher在本地正常工作,但是当我部署应用程序以GAE时,查询在数据库中找不到任何匹配项(我在两种环境中以相同的方式在数据库中创建条目) 查询是: user = users.get_current_user() _website_sect_name = 'TVplus_Access' account_chk = Account.chk_account(user.email(), _website_sect_name) nd

我有一个ndb查询,它可以使用Google App Engine Launcher在本地正常工作,但是当我部署应用程序以GAE时,查询在数据库中找不到任何匹配项(我在两种环境中以相同的方式在数据库中创建条目)

查询是:

user = users.get_current_user()
_website_sect_name = 'TVplus_Access'
account_chk = Account.chk_account(user.email(), _website_sect_name)
ndb的型号和功能如下:

DEFAULT_WEBSITE_NAME = 'TVplus_Access'

def access_lvl_key(website_sect_name=DEFAULT_WEBSITE_NAME):
    """Constructs a Datastore key for a Access_lvl entity with website_sect_name."""
    return ndb.Key('Access_lvl', website_sect_name)

class Account(ndb.Model):
    """Models an individual Access_lvl entry."""
    email = ndb.StringProperty(required=True)
    nickname = ndb.StringProperty(indexed=True)
    date = ndb.DateTimeProperty(auto_now_add=True)
    author = ndb.UserProperty()

    @classmethod
    def chk_account(self, _email, _website_sect_name):
        no_acct = 0
        try: 
            website_key = ndb.Key('Access_lvl', _website_sect_name)
            account_email = Account.query(Account.email == _email, ancestor=website_key).order(-Account.date).get().to_dict()
            return account_email
        except:
            return no_acct
添加用户的功能是:

class Adduser(webapp2.RequestHandler):
    def post(self):

        website_sect_name = self.request.get('website_sect_name',
                                      DEFAULT_WEBSITE_NAME)
        account = Account(parent=access_lvl_key(website_sect_name))

        if users.get_current_user():
            account.author = users.get_current_user()

        account.email = self.request.get('email')
        account.put()

        account.nickname = self.request.get('nickname')
        account.put()

        query_params = {'website_sect_name': website_sect_name}
        self.redirect('/useradmin?' + urllib.urlencode(query_params))
在我的本地计算机上,Account.chk_Account()的返回响应为:

{'date':datetime.datetime(2014,7,2,22,6,22,854000),'昵称':u'Roger','email':u'roger@test.com“,”作者“:用户。用户(电子邮件=”admin@test.com“,_user_id='1233002172171163669814')}


但是在部署服务器上,该函数从0的“no_acct”返回except代码,它告诉我chk_account()出于某种原因(电子邮件帐户)为空roger@test.com已添加到两种环境中的TVplus_访问)

据我所知,GAE远程控制面板有某种工具来检查数据库结构和条目。您能访问它并查看您添加的帐户是否真的存在吗?

问题在于chk_account=definition中存在。已从Account.query()中删除“.order(-Account.date)”。已更正的代码部分:

@classmethod
    def chk_account(self, _email, _website_sect_name):
        no_acct = 0
        try: 
            website_key = ndb.Key('Access_lvl', _website_sect_name)
            account_email = Account.query(Account.email == _email, ancestor=website_key).get().to_dict()
            return account_email
        except:
            return no_acct

那是个好主意。刚刚检查了数据存储查看器,我看到了具有正确id、电子邮件、昵称和作者的条目。如果我点击它显示的id:“解码的实体键:Access\u lvl:name=TVplus\u Access>Account:id=5707702298738688”以及属性。这看起来是正确的,但是当我点击“Access\u lvl:name=TVplus\u Access”时,它给了我实体键,但下面它说“这个实体不存在”——这似乎可能是问题所在?您是手动创建此行还是从应用程序内部创建此行,如果手动创建,可能会出现格式问题。我建议您完全删除这一行,并从应用程序内部添加它。如果您已经在应用程序内部执行了此操作,请尝试查询所有条目。查看是否包含。应用程序中创建的所有内容。当查看其中一个“帐户”实体时,没有列出父实体,因此存在问题。我将使用创建条目的代码编辑问题。检查应用程序引擎日志。可能需要为此添加新的数据存储索引。