AttributeError:'模块'对象没有属性' gets'记忆GAE

时间:2014-05-08 13:44:04

标签: python google-app-engine caching memcached

我有一个使用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的研究,我发现了这个讨论:

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

我做错了什么?

1 个答案:

答案 0 :(得分:4)

你错了:memcache模块具有gets功能。请参阅documentation

gets是memcache Client对象的一种方法:再次,请参阅the docs