我正在学习如何设置django-celery并且我收到此错误
[tasks]
. revamp.celery.debug_task
[2017-08-20 05:58:06,216: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.
Trying again in 2.00 seconds...
[2017-08-20 05:58:08,230: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.
Trying again in 4.00 seconds...
[2017-08-20 05:58:12,245: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.
Trying again in 6.00 seconds...
[2017-08-20 05:58:18,263: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.
Trying again in 8.00 seconds...
[2017-08-20 05:58:26,283: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.
Trying again in 10.00 seconds...
[2017-08-20 05:58:36,312: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.
Trying again in 12.00 seconds...
这是他们的文档http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
当我运行此命令时,出现上述错误
celery -A revamp worker -l info
我的django项目名为revamp,在revamp / revamp / celery.py这里是代码
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'revamp.settings')
app = Celery('revamp')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
答案 0 :(得分:1)
这是因为您的芹菜应用程序无法找到消息代理。请安装rabbitmq-server(sudo apt-get install rabbitmq-server)并启动(sudo service rabbitmq-server start)吧。如果已安装重新启动它将解决问题。