pydev 导入 GAE memcache 时出现错误

0 投票
1 回答
1326 浏览
提问于 2025-04-18 05:59

在我寻找一个支持webapp2的好Python开发环境(IDE)的过程中,有人建议我使用带有pydev插件的Eclipse。

我在一个干净的Eclipse版本上成功安装了它,并创建了一个GAE项目。一切看起来都很正常,除了memcache。奇怪的是,这个IDE无法编译以下的Python代码,尽管代码本身是完全合法的:

from google.appengine.api import memcache

class FlushMemCache(BlogHandler):
    def get(self):
        memcache.flush_all()
        self.redirect(BLOG_FRONT_URL)

我只收到一个错误提示:Undefined variable from import: flush_all。这个问题在memcache的所有方法中都出现。更奇怪的是,如果我不使用Eclipse直接在GAE上运行这段代码,网页可以正常加载,一切都没问题。

此外,当我按F2键聚焦并使用Eclipse的控制台测试一些代码时,我也遇到了以下错误:

import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
/usr/bin/python 2.7.4 (default, Sep 26 2013, 03:20:26) 
[GCC 4.7.3]
PyDev console: using default backend (IPython not available).
from google.appengine.api import memcache
memcache.set('hello world', 'ola')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/pedro/google_appengine/google/appengine/api/memcache/__init__.py", line 763, in set
    namespace=namespace)
  File "/home/pedro/google_appengine/google/appengine/api/memcache/__init__.py", line 868, in _set_with_policy
    time, '', namespace)
  File "/home/pedro/google_appengine/google/appengine/api/memcache/__init__.py", line 970, in _set_multi_async_with_policy
    (server_keys, user_key))
  File "/home/pedro/google_appengine/google/appengine/api/memcache/__init__.py", line 380, in _make_async_call
    rpc = create_rpc()
  File "/home/pedro/google_appengine/google/appengine/api/memcache/__init__.py", line 294, in create_rpc
    return apiproxy_stub_map.UserRPC('memcache', deadline, callback)
  File "/home/pedro/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 413, in __init__
    self.__rpc = CreateRPC(service, stubmap)
  File "/home/pedro/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 67, in CreateRPC
    assert stub, 'No api proxy found for service "%s"' % service
AssertionError: No api proxy found for service "memcache"

我是不是漏掉了什么配置细节?我该如何解决这个问题呢?

1 个回答

1

你确定Google App Engine的开发服务器已经启动了吗?我觉得这可能是你的问题。你的代码是正确的,但开发服务器需要先启动,才能响应你的请求并运行缓存机制。

如果你不想启动Google App Engine,只是想在你的项目中使用缓存库,你可以查看这个解决方案

撰写回答