gpt4 book ai didi

python - 程序运行 Pika 抛出 AMQPConnectionError

转载 作者:行者123 更新时间:2023-12-04 11:52:15 25 4
gpt4 key购买 nike

阅读此处找到的 Rabbit MQ Pika HelloWorld 教程:
https://www.rabbitmq.com/tutorials/tutorial-one-python.html
问题是,每当我运行接收脚本时,我都会收到此错误:

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
这是我试图运行的代码:
#!/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()

任何帮助深表感谢。非常感谢你。

最佳答案

您只需要在 PC 上安装 RabbitMQ,您就可以在另一个终端中使用以下命令简单地使用 docker 运行,然后重新运行您的代码

docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management

关于python - 程序运行 Pika 抛出 AMQPConnectionError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55718163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com