Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute 'Redis' when using Celery with Redis #2088

Open
jamesjohnson1025 opened this issue Jul 31, 2024 · 2 comments

Comments

@jamesjohnson1025
Copy link

I'm encountering an error when trying to use Celery with Redis in my Python project. Despite having installed both Celery and Redis, I'm getting the following error:

    class PrefixedStrictRedis(GlobalKeyPrefixMixin, redis.Redis):
AttributeError: 'NoneType' object has no attribute 'Redis'

This error occurs in the Kombu library, which is a dependency of Celery. I've already tried the following steps:

Installed Redis: pip install redis
Installed Celery: pip install celery

Verified that the Redis server is running
I checked that I am using the correct virtual environment

My environment:

Python version: 3.10
Operating System: macOS
Redis: 4.5.2
Celery: 5.4.0

I am using Redis docker. I tried testing using the below script and it returned true:

import redis

r = redis.Redis(host='localhost', port=6379, db=0)

try:
    r.ping()
    print("Successfully connected to Redis")
except redis.ConnectionError:
    print("Failed to connect to Redis")

What could be causing this error, and how can I resolve it? Is there a potential version conflict or misconfiguration that I'm overlooking?

The error is triggered when I try to execute the following train function using my FastAPI endpoint:

# api.py
api.post("/train")
def train():
    hello.delay()

# tasks.py
celery_app = Celery('tasks', broker='redis://localhost:6379/0')
celery_app.conf.update(result_backend='redis://localhost:6379/0')

@celery_app.task
def hello():
   print("Hello world")

@thedrow
Copy link
Member

thedrow commented Aug 14, 2024

Are you sure the redis package is installed in the same virtual environment as celery?

@swcasimiro
Copy link

pip install redis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants