Google app engine 无法使用应用程序引擎数据存储

Google app engine 无法使用应用程序引擎数据存储,google-app-engine,google-cloud-datastore,Google App Engine,Google Cloud Datastore,我已经使用了app engine的入门指南。但是我无法使用数据存储 运行指南中提供的简单代码时,出现“无法访问应用程序数据”错误 我的代码: import cgi import datetime import urllib import webapp2 from google.appengine.ext import db from google.appengine.api import users MAIN_PAGE_FOOTER_TEMPLATE = """\ <form act

我已经使用了app engine的入门指南。但是我无法使用数据存储

运行指南中提供的简单代码时,出现“无法访问应用程序数据”错误

我的代码:

import cgi
import datetime
import urllib
import webapp2

from google.appengine.ext import db
from google.appengine.api import users


MAIN_PAGE_FOOTER_TEMPLATE = """\
<form action="/sign?%s" method="post">
  <div><textarea name="content" rows="3" cols="60"></textarea></div>
  <div><input type="submit" value="Sign Guestbook"></div>
</form>
<hr>
<form>Guestbook name: <input value="%s" name="guestbook_name">
<input type="submit" value="switch"></form>
</body>
</html>
"""

class Greeting(db.Model):
"""Models an individual Guestbook entry with author, content, and date."""
author = db.StringProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)


def guestbook_key(guestbook_name=None):
"""Constructs a Datastore key for a Guestbook entity with guestbook_name."""
return db.Key.from_path('Guestbook', guestbook_name or 'default_guestbook')


class MainPage(webapp2.RequestHandler):

def get(self):
    self.response.write('<html><body>')
    guestbook_name = self.request.get('guestbook_name')

    # Ancestor Queries, as shown here, are strongly consistent with the High
    # Replication Datastore. Queries that span entity groups are eventually
    # consistent. If we omitted the ancestor from this query there would be
    # a slight chance that Greeting that had just been written would not
    # show up in a query.
    greetings = db.GqlQuery("SELECT * "
                            "FROM Greeting "
                            "WHERE ANCESTOR IS :1 "
                            "ORDER BY date DESC LIMIT 10",
                            guestbook_key(guestbook_name))

    for greeting in greetings:
        if greeting.author:
            self.response.write(
                '<b>%s</b> wrote:' % greeting.author)
        else:
            self.response.write('An anonymous person wrote:')
        self.response.write('<blockquote>%s</blockquote>' %
                                cgi.escape(greeting.content))

    # Write the submission form and the footer of the page
    sign_query_params = urllib.urlencode({'guestbook_name': guestbook_name})
    self.response.write(MAIN_PAGE_FOOTER_TEMPLATE %
                        (sign_query_params, cgi.escape(guestbook_name)))


class Guestbook(webapp2.RequestHandler):

def post(self):
    # We set the same parent key on the 'Greeting' to ensure each greeting
    # is in the same entity group. Queries across the single entity group
    # will be consistent. However, the write rate to a single entity group
    # should be limited to ~1/second.
    guestbook_name = self.request.get('guestbook_name')
    greeting = Greeting(parent=guestbook_key(guestbook_name))

    if users.get_current_user():
        greeting.author = users.get_current_user().nickname()

    greeting.content = self.request.get('content')
    greeting.put()

    query_params = {'guestbook_name': guestbook_name}
    self.redirect('/?' + urllib.urlencode(query_params))


app = webapp2.WSGIApplication([('/', MainPage),
                           ('/sign', Guestbook)],
                          debug=True)

我复制并粘贴了您的代码,它似乎正在工作(我必须更改格式) 你的app.yaml中有什么?(我把我的文件命名为aaa.py)这就是我使用的

application: somename
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: aaa.app

对于dev服务器,答案在stacktrace的最后一行

app“dev~helloworld”无法访问app“dev~hellolxmn”的数据

你可能有一个app.yaml,随着时间的推移,它的appid发生了变化,而你没有 创建了一个新的数据存储。您应该向我们展示您当前的app.yaml


我猜您的错误在产品中会有一点不同,所以在生产中显示错误的跟踪。

您应该能够通过清除数据存储来修复此问题。
application: somename
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: aaa.app