python-3.xflaskmemcachedwerkzeugpython-memcached

Werkzeug-0.9.4 and python3_memcached-1.51 doesn't work on Python 3.4


I'm using werkzeug.contrib.cache.MemcachedCache with python3_memcached-1.51 when I try to get\set data I get the following error: memcache.MemcachedKeyTypeError: Key must be str()'s here: https://github.com/eguven/python3-memcached/blob/master/memcache.py#L1039

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

The key type is bytes, not str. So I checked deeper.

Inside werkzeug.contrib.cache.MemcachedCache key is encoded into bytes (in Python3) like this:

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

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

What is correct fix for this? Monkey patch?


Solution

  • The fix is to upgrade to Werkzeug 0.10: https://github.com/mitsuhiko/werkzeug/commit/94bea60a1b8e26b586dcd7bc75b162a9909696a3