Werkzeug-0.9.4和python3_memcached-1.51在Python 3.4上不起作用

时间:2014-06-03 10:43:02

标签: python-3.x flask memcached werkzeug python-memcached

当我尝试获取\ set数据时,我正在使用werkzeug.contrib.cache.MemcachedCache和python3_memcached-1.51我收到以下错误:memcache.MemcachedKeyTypeError: Key must be str()'s此处: https://github.com/eguven/python3-memcached/blob/master/memcache.py#L1039

if not isinstance(key, str):
    raise Client.MemcachedKeyTypeError("Key must be str()'s")

密钥类型为bytes,而不是str。所以我进行了更深入的检查。

内部werkzeug.contrib.cache.MemcachedCache密钥编码为bytes(在Python3中),如下所示:

if isinstance(key, text_type):
    key = key.encode('utf-8')

https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/contrib/cache.py#L342

对此有何正确解决方法?猴子补丁?

1 个答案:

答案 0 :(得分:1)