当我是 运行 芹菜工人时出现 AttributeError

AttributeError when I'm running Celery worker

我正在尝试在我的 Django 应用程序中使用 celery 作为后台进程。 Django 版本为 1.4.8,最新适用的 celery 版本为 3.1.25。

我使用 Redis (3.1.0) 作为代理和后端,json 作为序列化程序。

当我启动 worker 时 celery -A celery_app worker -l info 我收到 属性错误 'unicode' object has no attribute 'iteritems'

我的 settings.py 文件:

BROKER_URL = 'redis://localhost'
CELERY_RESULT_BACKEND = 'redis://localhost/'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_STORE_ERRORS_EVEN_IF_IGNORED = True

celery_app.py:

import sys
from django.conf import settings
from celery import Celery

project_root = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(project_root, '../env'))
sys.path.insert(0, os.path.join(project_root, '../'))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
app = Celery('project')
app.config_from_object('project.settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS, force=True)

tasks.py:

@celery_app.task
def sample_task(x):
    return 'Test response'

我就是这样 运行 这个任务的:

sample_task.delay({'key': 'test'})

我收到以下错误:

File "/Users/user/project/venv/lib/python2.7/site-packages/redis/_compat.py", line 94, in iteritems
    return x.iteritems()
AttributeError: 'unicode' object has no attribute 'iteritems'

完整追溯:

[2019-01-31 16:43:08,909: ERROR/MainProcess] Unrecoverable error: AttributeError("'unicode' object has no attribute 'iteritems'",)
Traceback (most recent call last):
  File "/Users/user/project/venv/lib/python2.7/site-packages/celery/worker/__init__.py", line 206, in start
    self.blueprint.start(self)
  File "/Users/user/project/venv/lib/python2.7/site-packages/celery/bootsteps.py", line 123, in start
    step.start(parent)
  File "/Users/user/project/venv/lib/python2.7/site-packages/celery/bootsteps.py", line 374, in start
    return self.obj.start()
  File "/Users/user/project/venv/lib/python2.7/site-packages/celery/worker/consumer.py", line 280, in start
    blueprint.start(self)
  File "/Users/user/project/venv/lib/python2.7/site-packages/celery/bootsteps.py", line 123, in start
    step.start(parent)
  File "/Users/user/project/venv/lib/python2.7/site-packages/celery/worker/consumer.py", line 884, in start
    c.loop(*c.loop_args())
  File "/Users/user/project/venv/lib/python2.7/site-packages/celery/worker/loops.py", line 76, in asynloop
    next(loop)
  File "/Users/user/project/venv/lib/python2.7/site-packages/kombu/async/hub.py", line 340, in create_loop
    cb(*cbargs)
  File "/Users/user/project/venv/lib/python2.7/site-packages/kombu/transport/redis.py", line 1019, in on_readable
    self._callbacks[queue](message)
  File "/Users/user/project/venv/lib/python2.7/site-packages/kombu/transport/virtual/__init__.py", line 534, in _callback
    self.qos.append(message, message.delivery_tag)
  File "/Users/user/project/venv/lib/python2.7/site-packages/kombu/transport/redis.py", line 146, in append
    pipe.zadd(self.unacked_index_key, delivery_tag, time()) \
  File "/Users/user/project/venv/lib/python2.7/site-packages/redis/client.py", line 2320, in zadd
    for pair in iteritems(mapping):
  File "/Users/user/project/venv/lib/python2.7/site-packages/redis/_compat.py", line 94, in iteritems
    return x.iteritems()
AttributeError: 'unicode' object has no attribute 'iteritems'

我试图在互联网上找到问题,试图将另一个参数传递给任务。我不知道如何调试 celery 进程,也无法自己找到解决方案。请帮助我

这个 Celery 版本似乎不支持 Redis 3。尝试安装 Redis 2.10.6.