2 years ago

#58664

test-img

Saarsa

django celery delay function use guest user

Hello I want to use celery tasks in my Django project

When I run the celery -A proj worker -l INFO all good it connects to the rabbitmq server

But I have a problem when I run the task add.delay(1, 1) I get a response (403) ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.

In the logfile I can see 2022-01-16 23:15:51.898981+00:00 [erro] <0.1093.0> PLAIN login refused: user 'guest' - invalid credentials I understand celery delay function using the wrong user guest and not saar

my file in my project

celery.py

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
app = Celery('proj')

app.config_from_object('django.conf:settings', namespace='CELERY')

app.autodiscover_tasks()

settings.py

CELERY_TASK_TRACK_STARTED = True
CELERY_BROKER_URL = 'amqp://saar:1234567s@localhost'

init.py

from .celery import app as celery_app
__all__ = ('celery_app',)

tasks.py

from __future__ import absolute_import, unicode_literals
from celery import shared_task

@shared_task
def add(x, y):
    return x + y

my packages: Django 3.2.11, celery 5.2.3, flower 1.0.0, django-celery-beat 2.2.1

What can I do to fix it?

I found that if I import a task from the celery.py file before it works for me but how can i fix it if I only import from tasks.py file?

python

django

django-celery

0 Answers

Your Answer

Accepted video resources