6

I have python-memcached (1.57) and django-celery (3.1.17), celery (3.1.20) and python 3.5. I always get the error below when i try to implement http://docs.celeryproject.org/en/latest/tutorials/task-cookbook.html#ensuring-a-task-is-only-executed-one-at-a-time

Task tasks.live_task[a2ed1faf-0fce-4855-a206-40f2fbdae1a8] raised unexpected: TypeError("a bytes-like object is required, not 'str'",)
Traceback (most recent call last):
File "/app/current/venv/lib/python3.5/site-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/app/current/venv/lib/python3.5/site-packages/celery/app/trace.py", line 438, in __protected_call__
return self.run(*args, **kwargs)
File "/app/current/src/helps.py", line 62, in wrapper
if acquire():
File "/app/current/src/helps.py", line 57, in acquire
return cache.add(id, "true", time_out)
File "/app/current/venv/lib/python3.5/site-packages/django/core/cache/backends/memcached.py", line 80, in add
return self._cache.add(key, value, self.get_backend_timeout(timeout))
File "/app/current/venv/lib/python3.5/site-packages/memcache.py", line 633, in add
return self._set("add", key, val, time, min_compress_len, noreply)
File "/app/current/venv/lib/python3.5/site-packages/memcache.py", line 983, in _set
server, key = self._get_server(key)
File "/app/dashboard/current/venv/lib/python3.5/site-packages/memcache.py", line 413, in _get_server
serverhash = serverHashFunction(str(serverhash) + str(i))
File "/app/current/venv/lib/python3.5/site-packages/memcache.py", line 65, in cmemcache_hash
(((binascii.crc32(key) & 0xffffffff)
TypeError: a bytes-like object is required, not 'str'
qj2003
  • 117
  • 1
  • 10

1 Answers1

4

python-memchached is not supported on python 3.5 If you've used python-memchached, The following commands will help you.

pip uninstall python-memcached
pip install python3-memcached
Shin Kim
  • 3,685
  • 1
  • 24
  • 29
  • 2
    actually it's a trap. python3-memcached does work but it's discontinued and the official python-memcached only works with utf-8 encoded data. Supposedly there's a fix for it but for me it still blows up: https://github.com/linsomniac/python-memcached/issues/80 – Anderson Santos Jul 20 '16 at 12:16
  • 1
    That's right. python3-memcached is deprecated. It was just a py3 compatibility port of python-memcached which since then has added py23. – Shin Kim Jul 21 '16 at 07:41