WinError 10061. Problem with connecting to Redis

Viewed 18

The code I have:

   import...
   application = Flask(__name__)
   redis_client = Redis(application)
   celery_app = Celery('app', broker='redis://localhost:6379/0')


  @application.route('/')
  def hello_world():
    task = background_task.delay()
    task.wait()
    return 'Hello World!'


   @shared_task
   def background_task():
    delay = 5

    print("Running Task")
    print("Simulates the {delay} seconds")

    time.sleep(delay)

    return "Completed Task"


   if __name__ == '__main__':
      application.run()

The exception I get:

 OperationalError: [WinError 10061] No connection could be made because 
    the target machine actively refused it
    127.0.0.1 - - [07/Sep/2022 15:18:50] "GET / HTTP/1.1" 500 -

At first, I start Redis, Celery and then Flask. Celery connects to Redis without any problem. I run Celery with this command: 'celery -A app worker --pool=solo -l INFO'

0 Answers
Related