Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 应用程序引擎-使用memcache实现获取密钥错误_Python_Google App Engine_Memcached - Fatal编程技术网

Python 应用程序引擎-使用memcache实现获取密钥错误

Python 应用程序引擎-使用memcache实现获取密钥错误,python,google-app-engine,memcached,Python,Google App Engine,Memcached,我正在尝试实现Guido发布的代码,作为问题的答案。当我第一次加载页面并向memcache添加值时,一切似乎都正常工作,但当我重新加载页面并从memcache检索值时,我遇到了一个奇怪的错误: Traceback (most recent call last): File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 194, in Handle for

我正在尝试实现Guido发布的代码,作为问题的答案。当我第一次加载页面并向memcache添加值时,一切似乎都正常工作,但当我重新加载页面并从memcache检索值时,我遇到了一个奇怪的错误:

Traceback (most recent call last):
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 194, in Handle
    for chunk in result:
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/appstats/recording.py", line 1036, in appstats_wsgi_wrapper
    result = app(environ, appstats_start_response)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1519, in __call__
    response = self._internal_error(e)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "/appengineurlhere/mypythoncode.py", line 87, in get
    entitylist = retrieve("entitylist")
  File "/appengineurlhere/mypythoncode.py", line 53, in retrieve
    return pickle.loads(serialized)
  File "/base/python27_runtime/python27_dist/lib/python2.7/pickle.py", line 1382, in loads
    return Unpickler(file).load()
  File "/base/python27_runtime/python27_dist/lib/python2.7/pickle.py", line 858, in load
    dispatch[key](self)
KeyError: ':'
以下是存储/检索代码:

def store(key, value, chunksize=750000):
    serialized = pickle.dumps(value, 2)
    values = {}
    for i in xrange(0, len(serialized), chunksize):
        values['%s.%s' % (key, i//chunksize)] = serialized[i : i+chunksize]
    memcache.set_multi(values)

def retrieve(key):
    result = memcache.get_multi(['%s.%s' % (key, i) for i in xrange(32)])
    serialized = ''.join([v for v in result.values() if v is not None])
    return pickle.loads(serialized)
这就是我使用它的方式:

try:
  entitylist = retrieve("entitylist")
except EOFError:
  entitylist = MyModel.all().fetch(None)
  store("entitylist", entitylist)
其他奇怪之处:

  • 我在我的开发服务器上看不到这一点;只是生产应用程序引擎站点。(虽然我的开发服务器上的数据略有不同;但我相信它完全符合标准1MB memcache大小,其中生产数据更大。)
  • 当我在开发和生产管理面板上搜索“entitylist”时,AppEngine告诉我“没有这样的密钥”。然而,根据所显示的memcache的总大小(这是我实现memcache的唯一地方),显然有些东西正在被缓存

有人能告诉我应该看什么或修复什么吗?

有没有可能您有一些MyModel的旧实例与MyModel的当前定义不匹配?如果存在无法识别或丢失的属性,则在酸洗时可能会出现错误。

FYI:;如果使用set/get而不进行酸洗,那么代码是否有效?嗨,威尔。因为整体大小大于1MB,所以以常规方式进行memcache会失败。嗨,dragonx。非常有趣;我怎么知道是不是这样的呢?试着捕捉KeyError并在日志中打印序列化的字符串,然后你就可以看看发生了什么。