miguelgrinberg/flask-celery-example

Redis Error when running the example

shashanktupkar opened this issue · 8 comments

Get this error while running the example.
I installed the necessary requirements from the requirements.txt.
Got this error when I clicked on the Start Long Calculations on the Webpage. Any pointers would be appreciated.

D:\flask-celery-example-master>python app.py

  • Restarting with stat
  • Debugger is active!
  • Debugger PIN: 316-263-277
  • Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
    127.0.0.1 - - [06/Mar/2019 17:51:06] "GET / HTTP/1.1" 200 -
    127.0.0.1 - - [06/Mar/2019 17:51:06] "GET /favicon.ico HTTP/1.1" 404 -
    127.0.0.1 - - [06/Mar/2019 17:51:34] "POST / HTTP/1.1" 500 -
    Traceback (most recent call last):
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1836, in call
    return self.wsgi_app(environ, start_response)
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_compat.py", line 33, in reraise
    raise value
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_compat.py", line 33, in reraise
    raise value
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1461, in dispatch_request
    return self.view_functionsrule.endpoint
    File "D:\flask-celery-example-master\app.py", line 75, in index
    send_async_email.delay(msg)
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\celery\app\task.py", line 453, in delay
    return self.apply_async(args, kwargs)
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\celery\app\task.py", line 555, in apply_async
    **dict(self._get_exec_options(), **options)
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\celery\app\base.py", line 353, in send_task
    reply_to=reply_to or self.oid, **options
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\celery\app\amqp.py", line 305, in publish_task
    **kwargs
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\kombu\messaging.py", line 172, in publish
    routing_key, mandatory, immediate, exchange, declare)
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\kombu\connection.py", line 457, in ensured
    interval_max)
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\kombu\connection.py", line 369, in ensure_connection
    interval_start, interval_step, interval_max, callback)
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\kombu\utils_init
    .py", line 246, in retry_over_time
    return fun(*args, **kwargs)
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\kombu\connection.py", line 237, in connect
    return self.connection
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\kombu\connection.py", line 741, in connection
    self._connection = self._establish_connection()
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\kombu\connection.py", line 696, in establish_connection
    conn = self.transport.establish_connection()
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\kombu\transport\virtual_init
    .py", line 809, in establish_connection
    self.avail_channels.append(self.create_channel(self))
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\kombu\transport\virtual_init
    .py", line 791, in create_channel
    channel = self.Channel(connection)
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\kombu\transport\redis.py", line 456, in init
    self._pool.disconnect()
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\redis\connection.py", line 898, in disconnect
    connection.disconnect()
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\kombu\transport\redis.py", line 819, in disconnect
    channel._on_connection_disconnect(self)
    File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\kombu\transport\redis.py", line 476, in _on_connection_disconnect
    raise get_redis_ConnectionError()
    redis.exceptions.ConnectionError
    127.0.0.1 - - [06/Mar/2019 17:51:45] "POST /longtask HTTP/1.1" 500 -
    127.0.0.1 - - [06/Mar/2019 17:51:45] "GET /?debugger=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
    127.0.0.1 - - [06/Mar/2019 17:51:45] "GET /?debugger=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 -
    127.0.0.1 - - [06/Mar/2019 17:51:45] "GET /?debugger=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
    127.0.0.1 - - [06/Mar/2019 17:51:45] "GET /?debugger=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1" 200 -
    127.0.0.1 - - [06/Mar/2019 17:51:45] "GET /?debugger=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
    127.0.0.1 - - [06/Mar/2019 17:51:45] "GET /?debugger=yes&cmd=resource&f=console.png HTTP/1.1" 200 -

Are you running a redis service? The error indicates the application cannot connect to it. Redis is an external dependency, you need to install it and run separately.

Ok thanks for the comment I was not aware of it. I installed and ran the redis-server.exe but still after clicking on "Start Long Calculation" I do not see any updates on the page. It is stuck to 0% pending... Also I am not able to send the email when I enter my email id and click on send. Can you guide? TIA

@shashanktupkar did you check the Flask and Celery terminals for errors?

@miguelgrinberg I got it. Before your comment I did not know that I have to run celery also using command "celery -A app.celery worker". I am using Windows and basically have 3 cmd prompts open. Is there a way I can start the redis server and app.celery working in background?

Thanks again @miguelgrinberg
P.S: Sorry I do not have much experience on Web Development or application side software. I am more of a low level software/driver developer.

When you are developing it is normal to open several terminals to run the different components, as you often want to see the output of all of them. You can probably install Redis as a service on Windows, and that will eliminate one of the processes.

If you want to implement a more robust solution that is good for a production system and you need to stay on Windows, then I recommend that you start using the WSL (Windows Subsystem for Linux). Actually I recommend the WSL for development as well.

Thanks for the advice @miguelgrinberg Appreciate it! I am just doing some initials developments on the Windows but will be running it finally on a Linux/Ubuntu system. So if I understood your previous comment properly, in Linux/Ubuntu systems, opening and starting redis and celery service will not be required. Is it right?

Oh no, you will also need to start everything on Linux, but for third party services such as redis most linux distributions provide it as a service that starts automatically. Your own processes will be handled manually during development, and as services in production. I recommended Linux for robustness as a server platform. You'll still need to figure out a way to run your processes in the background if that is what you want to do.

Got you! Again thanks for your help @miguelgrinberg :)