2016-02-07 44 views
6

我有python-memcached(1.57)和django-celery(3.1.17),celery(3.1.20)和python 3.5。我總是得到下面當我嘗試錯誤來實現http://docs.celeryproject.org/en/latest/tutorials/task-cookbook.html#ensuring-a-task-is-only-executed-one-at-a-time需要類似字節的對象,而不是'str' - error

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

該錯誤很可能與您的python版本有關。嘗試使用'bytes(string,encoding =「UTF-8」)'轉換爲字節。 –

+1

嘗試使用'python3-memcached' –

+0

@DerekKwok'python3-memcached> = 1.51'或者是錨定到1.51特別重要? – tdelaney

回答

5

python-memchached如果你已經使用python-memchached,下面的命令將幫助你不支持python 3.5

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

實際上它是一個陷阱。 python3-memcached可以工作,但是它已經停止了,官方的python-memcached只能用於utf-8編碼的數據。據說有一個修復它,但對我來說,它仍然爆炸:https://github.com/linsomniac/python-memcached/issues/80 –

+0

是的。 python3-memcached已棄用。它只是python-memcached的一個py3兼容端口,從那時起它已經添加了py23。 –

相關問題