Program Running Pika Throwing AMQPConnectionError
Asked Answered
S

6

13

Going through the Rabbit MQ Pika HelloWorld tutorial found here: https://www.rabbitmq.com/tutorials/tutorial-one-python.html

The problem is, I keep getting this error whenever I run my receive script:

Traceback (most recent call last):
  File "receive.py", line 5, in <module>
    pika.ConnectionParameters(host='localhost'))

  File "C:\Users\Colin Warn\PycharmProjects\untitled2\venv\lib\site-packages\pika\adapters\blocking_connection.py", line 360, in __init__
    self._impl = self._create_connection(parameters, _impl_class)

  File "C:\Users\Colin Warn\PycharmProjects\untitled2\venv\lib\site-packages\pika\adapters\blocking_connection.py", line 451, in _create_connection
 
raise self._reap_last_connection_workflow_error(error)

pika.exceptions.AMQPConnectionError

Here's the code I'm attempting to run:

#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(
    pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='hello')


def callback(ch, method, properties, body):
    print(" [x] Received %r" % body)


channel.basic_consume(
    queue='hello', on_message_callback=callback, auto_ack=True)

print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()

Any help is much appreciated. Thank you so much in advance.

Spirituel answered 17/4, 2019 at 0:9 Comment(5)
Do you have a rabbit server running in your machine?Oilcup
Not sure how to check. I've also recreated their send.py script that I thought would create one, but it just sends me the same error. I have more than 200 MB on my disk drive, so I'm not sure what else would be causing this.Spirituel
You have to install a rabbit in your machine check out this rabbitmq.com/download.html after installing rabbit server go back and rerun the script. I hope it goes well.Oilcup
That fixed it, thank you!Spirituel
If you already have installed rabbitmq on your machine make sure the connection uri is correctCleanshaven
S
23

All you need to do is installing RabbitMQ in your PC. You can simply run with docker using the command below in another terminal, and re-run your code

docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
Surgy answered 4/1, 2021 at 10:59 Comment(1)
sudo docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management in my case it was run as super user.Antagonistic
S
6

You need to install RabbitMQ on your machine: https://rabbitmq.com/download.html

After installing RabbitMQ server re-run the script.

Spirituel answered 17/4, 2019 at 4:30 Comment(0)
E
3

Follow these steps:

  1. sudo apt-get install rabbitmq-server
  2. sudo systemctl start rabbitmq-server
  3. sudo systemctl enable rabbitmq-server
Excurvate answered 3/12, 2021 at 22:37 Comment(2)
The questioner seems to be a windows user. But you seem to have answered when using ubuntu OS.Aylward
This helped me for my linux issue. I needed to install this for PIKA.Careless
B
2

I get a different solution, instead of using host='localhost', use the rabbitmq docker container ipaddress (in my case it was 172.17.0.2), you can get that ip with the command:

docker inspect <container_id>
Bryna answered 20/3, 2023 at 4:22 Comment(1)
This fixed my issue, didn't see this answer anywhere else. Thank you!Shimkus
R
0

For me this problem arises when i updated my system.

And the possible reasons are either rabbitmq-server is not installed or rabbitmq-server is not running.

try to run the below command in ubuntu

sudo systemctl status rabbimtmq-server

if server is not running, use below command to start the server.

sudo systemctl restart rabbitmq-server

if everthing is fine, then your code will run without any problem.

In case if your are unable to start/restart the server, the re-install the rabbitmq from below link.

rabbitmq installation guide

In my case, i solved the problem by reinstalling the rabbitmq.

Rici answered 14/6, 2023 at 13:29 Comment(0)
D
0

I also faced the same issue. Then I enabled (open) the 5672 port in my hosting device. Then it solved.

Demonolatry answered 24/8, 2023 at 9:16 Comment(1)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewChapter

© 2022 - 2024 — McMap. All rights reserved.