Django Celery - Cannot connect to amqp://[email protected]:5672//

PythonDjangoCelery

Python Problem Overview


I'm trying to set up Django-Celery. I'm going through the tutorial

http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html

when I run $ python manage.py celery worker --loglevel=info

I get

[Tasks]


/Users/msmith/Documents/dj/venv/lib/python2.7/site-packages/djcelery/loaders.py:133:     UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in     production environments!
warnings.warn('Using settings.DEBUG leads to a memory leak, never '

[2013-08-08 11:15:25,368: WARNING/MainProcess] /Users/msmith/Documents/dj/venv/lib/python2.7/site-packages/djcelery/loaders.py:133: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments!
warnings.warn('Using settings.DEBUG leads to a memory leak, never '

[2013-08-08 11:15:25,369: WARNING/MainProcess] celery@sfo-mpmgr ready.
[2013-08-08 11:15:25,382: ERROR/MainProcess] consumer: Cannot connect to     amqp://[email protected]:5672/celeryvhost: [Errno 61] Connection refused.
Trying again in 2.00 seconds...

has anyone encountered this issue before?

settings.py

# Django settings for summertime project.
import djcelery
djcelery.setup_loader()

BROKER_URL = 'amqp://guest:guest@localhost:5672/'

...

INSTALLED_APPS = {
    ...
    'djcelery',
    'celerytest'
}

wsgi.py

import djcelery
djcelery.setup_loader()

Python Solutions


Solution 1 - Python

Update Jan 2022: This answer is outdated. As suggested in comments, please refer to this link

The problem is that you are trying to connect to a local instance of RabbitMQ. Look at this line in your settings.py

BROKER_URL = 'amqp://guest:guest@localhost:5672/'

If you are working currently on development, you could avoid setting up Rabbit and all the mess around it, and just use a development version of a message queue with the Django database.

Do this by replacing your previous configuration with:

BROKER_URL = 'django://'

...and add this app:

INSTALLED_APPS += ('kombu.transport.django', )

Finally, launch the worker with:

./manage.py celery worker --loglevel=info

Source: http://docs.celeryproject.org/en/latest/getting-started/brokers/django.html

Solution 2 - Python

I got this error because rabbitmq was not started. If you installed rabbitmq via brew you can start it using brew services start rabbitmq

Solution 3 - Python

you can add these lines to your settings.py :

CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'

and run :

celery -A yourProjectName worker -l info

Solution 4 - Python

If you are workling on a production environment,

You have to first install and setup a rabbitmq server. You can refer rabbitmq website for installation steps.

In settings you have to write this lines:

CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
BROKER_URL = 'amqp://guest:guest@localhost:5672//'

After all setup of rabitmq server you have to run this two command,

export C_FORCE_ROOT='true'
celery -A transcoder(name of app) worker --loglevel=info

Solution 5 - Python

If all above solutions are not working, you can try with this: turn off your network connection (wifi or wire).

It's so weird but sometime it's work for me!

Seem it relates to the local network device instead of RabbitMQ service.

My screen recording: https://drive.google.com/file/d/13t35Lzh3JLsCbGjRag0uiDhcYz1JuHq7/view?usp=sharing

Solution 6 - Python

Make sure you run the rabbit server in global, in my case that was the issue.

Solution 7 - Python

This error means celery backend settings is not proper so it is not able to connect to backend.

If you just started tutorial celery with django . You can try below settings.

CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672//'
CELERY_RESULT_BACKEND = 'db+sqlite:///results.db'

Solution 8 - Python

While you are installing Celery via pip you should select the version that you want to work with such as redis, rabbitmq, django etc.

As referred in docs: https://pypi.org/project/celery/

> Bundles Celery also defines a group of bundles that can be used to install Celery and the dependencies for a given feature. > > You can specify these in your requirements or on the pip command-line by using brackets. Multiple bundles can be specified by separating them by commas. > Example:

$ pip install "celery[librabbitmq]"

$ pip install "celery[librabbitmq,redis,auth,msgpack]"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIdeoREXView Question on Stackoverflow
Solution 1 - PythonfiniteautomataView Answer on Stackoverflow
Solution 2 - PythonxiaoView Answer on Stackoverflow
Solution 3 - PythonAmir.SView Answer on Stackoverflow
Solution 4 - Pythonjatinkumar patelView Answer on Stackoverflow
Solution 5 - PythonCK.NguyenView Answer on Stackoverflow
Solution 6 - PythonsabarinathjvView Answer on Stackoverflow
Solution 7 - PythonVishvajeet RamanujView Answer on Stackoverflow
Solution 8 - PythonfurkanaydView Answer on Stackoverflow