pythondjangocachingmemcachedpython-memcached

'str' does not support the buffer interface with Memcached


I am using django 1.7 with python3.4. I recently installed Memcached and am trying to use it with python-memcached as per site cache. But once I define the default cache backend in the settings.py, my application stops working throwing this error:

'str' does not support the buffer interface

The installed middleware and the traceback is:

Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.cache.UpdateCacheMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.cache.FetchFromCacheMiddleware')


Traceback:
File "C:\Python34\lib\site-packages\django\core\handlers\base.py" in get_response
  87.                 response = middleware_method(request)
File "C:\Python34\lib\site-packages\django\middleware\cache.py" in process_request
  148.         cache_key = get_cache_key(request, self.key_prefix, 'GET', cache=self.cache)
File "C:\Python34\lib\site-packages\django\utils\cache.py" in get_cache_key
  223.     headerlist = cache.get(cache_key, None)
File "C:\Python34\lib\site-packages\django\core\cache\backends\memcached.py" in get
  82.         val = self._cache.get(key)
File "C:\Python34\lib\site-packages\memcache.py" in get
  1002.         return self._get('get', key)
File "C:\Python34\lib\site-packages\memcache.py" in _get
  986.             return _unsafe_get()
File "C:\Python34\lib\site-packages\memcache.py" in _unsafe_get
  957.                 server.send_cmd("%s %s" % (cmd, key))
File "C:\Python34\lib\site-packages\memcache.py" in send_cmd
  1299.         self.socket.sendall(cmd + '\r\n')

Exception Type: TypeError at /ask/
Exception Value: 'str' does not support the buffer interface

Please tell me what is the problem and the solution. Does python-memcache binding not work with python3.4


Solution

  • Update: This answer is outdated. Please check the other answer below. .....................................................................................................................

    The python-memcached library isn't compatible with Python 3.4. pylibmc doesn't support python3 as well.

    python3-memcached is outdated/unmaintained python3 port of the pure python memcache client implementation.

    Redis is strongly considered as better alternative to memcacahed in most cases. redis-py supports python3.