Ronak Agrawal Ronak Agrawal - 1 year ago 418
Python Question

Getting “pika.exceptions.ConnectionClosed” error while using rabbitmq in python

I am trying to use rabbitmq in python.
My code is:

import pika

if __name__ == '__main__':
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))

I am running this file using:


Error Signature:

Traceback (most recent call last):
File "", line 4, in <module>
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pika/adapters/", line 339, in __init__
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pika/adapters/", line 374, in _process_io_for_connection_setup
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pika/adapters/", line 395, in _flush_output
raise exceptions.ConnectionClosed()

Already referred this , but i dont have any sleep in my code.
Not really sure what could go wrong.
Please let me know if I am missing something obvious.

Answer Source

The issue was with rabbitmqctl. Reconfigured it, Restarted service, and the issue is fixed.

  1. Make sure rabbitmqctl is installed(if installed, uninstall it and re-install;when you just enter rabbitmqctl, it should display the help)
  2. rabbitmqctl start_app

TIP: I tried installing first using 'brew',but for some reason, I was not able to get it right. So installed, rabbitmqctl as a separate package and added to PATH

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download