Django Celery socket.error: [Errno 111] Connection refused

10,624

Solution 1

Launch from manage.py shell...

sudo python manage.py celery status

This will solve your issue.

Solution 2

In my case, I had to add the following lines at the __init__.py file at the package containing settings.py and celery.py files:

# -*- coding: utf-8 -*-
from __future__ import absolute_import

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app

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

Share:
10,624
Prometheus
Author by

Prometheus

Updated on July 02, 2022

Comments

  • Prometheus
    Prometheus almost 2 years

    When running the command celery status on my production server I get this error:

    But, Celery works and the worker do run, what is this error and why can I not run this command?

    ubuntu@ip-10-32-9-39:/srv/project/logs/celery$ celery status
    Traceback (most recent call last):
      File "/usr/local/bin/celery", line 9, in <module>
        load_entry_point('celery==3.0.11', 'console_scripts', 'celery')()
      File "/usr/local/lib/python2.7/dist-packages/celery/__main__.py", line 14, in main
        main()
      File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 946, in main
        cmd.execute_from_commandline(argv)
      File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 890, in execute_from_commandline
        super(CeleryCommand, self).execute_from_commandline(argv)))
      File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 179, in execute_from_commandline
        return self.handle_argv(prog_name, argv[1:])
      File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 882, in handle_argv
        return self.execute(command, argv)
      File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 857, in execute
        return cls(app=self.app).run_from_argv(self.prog_name, argv)
      File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 142, in run_from_argv
        return self(*args, **options)
      File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 112, in __call__
        ret = self.run(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 652, in run
        .run('ping', **dict(kwargs, quiet=True, show_body=False))
      File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 505, in run
        return self.do_call_method(args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 527, in do_call_method
        replies = handler(method, *args[1:], **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 570, in call
        return getattr(i, method)(*args)
      File "/usr/local/lib/python2.7/dist-packages/celery/app/control.py", line 79, in ping
        return self._request('ping')
      File "/usr/local/lib/python2.7/dist-packages/celery/app/control.py", line 54, in _request
        timeout=self.timeout, reply=True))
      File "/usr/local/lib/python2.7/dist-packages/celery/app/control.py", line 260, in broadcast
        channel=channel)
      File "/usr/local/lib/python2.7/dist-packages/kombu/pidbox.py", line 235, in _broadcast
        chan = channel or self.connection.default_channel
      File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 748, in default_channel
        self.connection
      File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 733, in connection
        self._connection = self._establish_connection()
      File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 692, in _establish_connection
        conn = self.transport.establish_connection()
      File "/usr/local/lib/python2.7/dist-packages/kombu/transport/pyamqp.py", line 109, in establish_connection
        heartbeat=conninfo.heartbeat)
      File "/usr/local/lib/python2.7/dist-packages/amqp/connection.py", line 136, in __init__
        self.transport = create_transport(host, connect_timeout, ssl)
      File "/usr/local/lib/python2.7/dist-packages/amqp/transport.py", line 250, in create_transport
        return TCPTransport(host, connect_timeout)
      File "/usr/local/lib/python2.7/dist-packages/amqp/transport.py", line 95, in __init__
        raise socket.error, msg
    socket.error: [Errno 111] Connection refused
    

    Settings...

    CELERYD_NODES="w1 w2 w3"
    
    # Where to chdir at start.
    CELERYD_CHDIR="/srv/project/"
    
    # How to call "manage.py celeryd_multi"
    CELERYD_MULTI="$CELERYD_CHDIR/manage.py celeryd_multi"
    
    # How to call "manage.py celeryctl"
    CELERYCTL="$CELERYD_CHDIR/manage.py celeryctl"
    
    # Extra arguments to celeryd
    CELERYD_OPTS="--time-limit=300 --concurrency=8"
    
    # %n will be replaced with the nodename.
    CELERYD_LOG_FILE="/srv/project/logs/celery/%n.log"
    CELERYD_PID_FILE="/srv/project/celery/%n.pid"
    
    # Workers should run as an unprivileged user.
    CELERYD_USER="ubuntu"
    CELERYD_GROUP="ubuntu"
    
    # Name of the projects settings module.
    export DJANGO_SETTINGS_MODULE="project.settings"
    
  • Glyn Jackson
    Glyn Jackson almost 10 years
    @chachan sudo is just for elevated privileges. If you don't need it then you are doing something right!
  • cold_coder
    cold_coder almost 9 years
    Its still giving [Errno 111] Connection refused
  • Glyn Jackson
    Glyn Jackson almost 9 years
    @cold_coder It's a connection refused message so check you have the correct IP, username or password.