2013-04-16 23 views
0

我已經使用了應用引擎的入門指南,但我無法使用數據存儲。無法使用應用引擎數據存儲

運行指南中提供的簡單代碼時,出現「無法訪問應用程序數據」錯誤。

我的代碼:

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) 

我已經上傳服務器上的應用程序,但仍然得到同樣的錯誤。

Traceback (most recent call last): 
    File "/home/laxman/google_appengine/lib/webapp2/webapp2.py", line 1535, in __call__ 
rv = self.handle_exception(request, response, e) 
    File "/home/laxman/google_appengine/lib/webapp2/webapp2.py", line 1529, in __call__ 
rv = self.router.dispatch(request, response) 
    File "/home/laxman/google_appengine/lib/webapp2/webapp2.py", line 1278, in     default_dispatcher 
return route.handler_adapter(request, response) 
File "/home/laxman/google_appengine/lib/webapp2/webapp2.py", line 1102, in __call__ 
return handler.dispatch() 
File "/home/laxman/google_appengine/lib/webapp2/webapp2.py", line 572, in dispatch 
return self.handle_exception(e, self.app.debug) 
File "/home/laxman/google_appengine/lib/webapp2/webapp2.py", line 570, in dispatch 
return method(*args, **kwargs) 
File "/home/laxman/helloworld/helloworld.py", line 51, in get 
for greeting in greetings: 
File "/home/laxman/google_appengine/google/appengine/ext/db/__init__.py", line 2326, in next 
return self.__model_class.from_entity(self.__iterator.next()) 
File "/home/laxman/google_appengine/google/appengine/datastore/datastore_query.py", line 2892, in next 
next_batch = self.__batcher.next() 
File "/home/laxman/google_appengine/google/appengine/datastore/datastore_query.py", line 2754, in next 
return self.next_batch(self.AT_LEAST_ONE) 
File "/home/laxman/google_appengine/google/appengine/datastore/datastore_query.py", line 2791, in next_batch 
batch = self.__next_batch.get_result() 
File "/home/laxman/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 604, in get_result 
return self.__get_result_hook(self) 
File "/home/laxman/google_appengine/google/appengine/datastore/datastore_query.py", line 2528, in __query_result_hook 
self._batch_shared.conn.check_rpc_success(rpc) 
File "/home/laxman/google_appengine/google/appengine/datastore/datastore_rpc.py", line 1224, in check_rpc_success 
raise _ToDatastoreError(err) 
BadRequestError: app "dev~helloworld" cannot access app "dev~hellolxmn"'s data 

回答

2

對於開發服務器答案是你的你的堆棧跟蹤的最後一行。

app "dev~helloworld" cannot access app "dev~hellolxmn"'s data

,你可能會有哪些改變它的appid,隨着時間的推移和app.yaml的你有沒有 創造了一個新的數據存儲。你應該告訴我們你現在的app.yaml。

我的猜測是你的錯誤會在產品上有點不同,所以在生產中顯示錯誤的痕跡。

+0

您應該可以通過清除數據存儲來解決此問題。 – dragonx

0

我複製並粘貼您的代碼,它似乎是工作(我不得不改變格式化) 什麼是你的app.yaml? (我叫我的文件aaa.py)這是我用過

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

handlers: 
- url: /.* 
    script: aaa.app 
相關問題