【问题标题】:AttributeError: 'module' object has no attribute 'gets' memcache GAEAttributeError:“模块”对象没有属性“获取”内存缓存 GAE
【发布时间】:2014-05-08 13:44:04
【问题描述】:

我有一个使用 GAE 的简单 Python 程序,并且我正在使用 GAE 的 memcache 模块来确保在更新缓存时不会搞砸:

from google.appengine.api import memcache

class NewPost(BlogHandler):
    def get(self):
        self.render("newpost.html")

    def post(self):

        #update cache for the front page
        val, unique = memcache.gets(FRONT_PAGE_KEY)
        for p in val:
            logging.warning(p)

现在这段代码应该可以毫无问题地运行,但是当我使用 post 方法时,它会爆炸:

Traceback (most recent call last):
  File "/home/pedro/google_appengine/google/appengine/runtime/wsgi.py", line 266, in Handle
    result = handler(dict(self._environ), self._StartResponse)
  File "/home/pedro/google_appengine/lib/webapp2-2.3/webapp2.py", line 1519, in __call__
    response = self._internal_error(e)
  File "/home/pedro/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/home/pedro/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/home/pedro/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/home/pedro/google_appengine/lib/webapp2-2.3/webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "/home/pedro/google_appengine/lib/webapp2-2.3/webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/home/pedro/google_appengine/lib/webapp2-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "/home/pedro/google_appengine/hw6/blog.py", line 172, in post
    val, unique = memcache.gets(FRONT_PAGE_KEY)
AttributeError: 'module' object has no attribute 'gets'
INFO     2014-05-08 13:36:49,525 module.py:639] default: "POST /blog/newpost HTTP/1.1" 500 -

这根本没有意义,特别是因为我知道 memcache 有一个名为 gets(key) 的方法:

根据我对 stackoverflow 的研究,我发现了这个讨论:

所以我已刷新缓存并删除了所有本地数据库的内容,但我仍然收到错误消息。

我做错了什么?

【问题讨论】:

标签: python google-app-engine caching memcached


【解决方案1】:

你错了:memcache 模块确实没有gets 函数。请参阅documentation

gets 是内存缓存Client 对象的一个​​方法:同样,参见the docs

【讨论】:

  • 好吧,你的回答让我走上了一条最终解决我的问题的道路!如果你这么好心,你能问这个链接到你的答案吗? neopythonic.blogspot.pt/2011/08/… 它真的解释了一切,我也得到了一些例子!等待选择答案的时间结束后,我会立即选择它!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-30
  • 2010-11-18
相关资源
最近更新 更多