2016-02-07 11 views
6

Ho python-memcached (1.57) e django-celery (3.1.17), sedano (3.1.20) e python 3.5. Ho sempre trovato l'errore sotto quando provo a implementare http://docs.celeryproject.org/en/latest/tutorials/task-cookbook.html#ensuring-a-task-is-only-executed-one-at-a-timeè richiesto un oggetto simile a un byte, non "str" ​​- errore

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' 
+1

L'errore è molto probabilmente correlato alla versione di Python. Prova a convertire in byte usando 'bytes (string, encoding =" UTF-8 ")'. –

+1

Provare a usare 'python3-memcached' –

+0

@DerekKwok' python3-memcached> = 1.51' o è ancorante a 1.51 specificamente importante? – tdelaney

risposta

5

python-memchached non è supportato su python 3.5 Se hai utilizzato python-memchached, i seguenti comandi vi aiuterà.

pip uninstall python-memcached 
pip install python3-memcached 
+1

in realtà è una trappola. python3-memcached funziona ma è fuori produzione e il funzionario python-memcached funziona solo con i dati codificati utf-8. Presumibilmente c'è una soluzione per questo, ma per me ancora esplode: https://github.com/linsomniac/python-memcached/issues/80 –

+0

Esatto. python3-memcached è deprecato. Era solo una porta di compatibilità py3 di python-memcached che da allora ha aggiunto py23. –

Problemi correlati