0

Currently using django and celery i have done my configuration and installed redis and redis is actually active i have check using the cli also when i run python manage.py shell and run a task it works perfectly but when i access the task by calling it from a view i get this error

    Internal Server Error: /contact/
Traceback (most recent call last):
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/utils/functional.py", line 30, in __call__
    return self.__value__
AttributeError: 'ChannelPromise' object has no attribute '__value__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/amqp/transport.py", line 188, in _connect
    entries = socket.getaddrinfo(
  File "/usr/local/lib/python3.9/socket.py", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -9] Address family for hostname not supported
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/connection.py", line 446, in _reraise_as_library_errors
    yield
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/connection.py", line 433, in _ensure_connection
    return retry_over_time(
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/utils/functional.py", line 312, in retry_over_time
    return fun(*args, **kwargs)
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/connection.py", line 877, in _connection_factory
    self._connection = self._establish_connection()
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/connection.py", line 812, in _establish_connection
    conn = self.transport.establish_connection()
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/transport/pyamqp.py", line 201, in establish_connection
    conn.connect()
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/amqp/connection.py", line 323, in connect
    self.transport.connect()
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/amqp/transport.py", line 129, in connect
    self._connect(self.host, self.port, self.connect_timeout)
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/amqp/transport.py", line 197, in _connect
    raise (e
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/amqp/transport.py", line 213, in _connect
    self.sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/django/views/generic/base.py", line 84, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/django/views/generic/base.py", line 119, in dispatch
    return handler(request, *args, **kwargs)
  File "/mnt/c/Users/Codertjay/PycharmProjects/freelance/Gimsap-Ecommerce/home/views.py", line 102, in post
    send_support_message.delay(
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/celery/app/task.py", line 425, in delay
    return self.apply_async(args, kwargs)
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/celery/app/task.py", line 575, in apply_async
    return app.send_task(
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/celery/app/base.py", line 788, in send_task
    amqp.send_task_message(P, name, message, **options)
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/celery/app/amqp.py", line 510, in send_task_message
    ret = producer.publish(
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/messaging.py", line 177, in publish
    return _publish(
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/connection.py", line 523, in _ensured
    return fun(*args, **kwargs)
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/messaging.py", line 186, in _publish
    channel = self.channel
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/messaging.py", line 209, in _get_channel
    channel = self._channel = channel()
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/utils/functional.py", line 32, in __call__
    value = self.__value__ = self.__contract__()
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/messaging.py", line 225, in <lambda>
    channel = ChannelPromise(lambda: connection.default_channel)
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/connection.py", line 895, in default_channel
    self._ensure_connection(**conn_opts)
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/connection.py", line 433, in _ensure_connection
    return retry_over_time(
  File "/usr/local/lib/python3.9/contextlib.py", line 135, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/codertjay/.virtualenvs/Gimsap-Ecommerce/lib/python3.9/site-packages/kombu/connection.py", line 450, in _reraise_as_library_errors
    raise ConnectionError(str(exc)) from exc
kombu.exceptions.OperationalError: [Errno 111] Connection refused

This is my celery configuration i am currently using and i am using i have installed redis with pip and also the cli on system but still i have tried changing this configuration but it only works if i access the task by calling it on my own

 import os

from celery import Celery
from django.conf import settings

from Gimsap.settings import CELERY_BROKER_URL

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Gimsap.settings')

BROKER_URL = "redis://localhost:6379/1"

# used redis broker if it exists
app = Celery('Gimsap', namespace='CELERY')

app.config_from_object('django.conf:settings')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks(settings.INSTALLED_APPS)

app.conf.broker_url = BROKER_URL
CELERY_BROKER_URL = BROKER_URL

app.conf.beat_schedule = {

    """'
    Test celery worker
    send_admin_message': {
        'task': 'home.tasks.test_task',
        'schedule': 3,
    },"""
}


@app.task(bind=True)
def debug_task(self):
    print(f'Request: {self.request!r}')
Codertjay
  • 588
  • 8
  • 13

1 Answers1

0

I have been on this problem for a hours but finally I made sure my redis server was up which it has always been but i added some configuration to my Celery.py by adding the keyword borker and borker url andd it started working fine

 import os

from celery import Celery
from django.conf import settings

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Gimsap.settings')

# used redis broker if it exists
app = Celery('Gimsap', broker="redis://localhost:6379", backend="redis://localhost:6379")

app.config_from_object('django.conf:settings')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks(settings.INSTALLED_APPS)
BROKER_URL = "redis://localhost:6379"
broker_url = "redis://localhost:6379"
app.conf.broker_url = BROKER_URL
CELERY_BROKER_URL = BROKER_URL

app.conf.beat_schedule = {

    """'
    Test celery worker
    send_admin_message': {
        'task': 'home.tasks.test_task',
        'schedule': 3,
    },"""
}


@app.task
def debug_task():
    print(f'Request: ')

The way i debug it was the @shared_task wasn't using the default configuration Because the @app.task in the celery was working well that when i realized the celery wasn't accessing my redis server

Codertjay
  • 588
  • 8
  • 13