gpt4 book ai didi

python - 套接字.gaierror gaierror : [Errno -2] Name or service not known - pika rabbitMQ

转载 作者:行者123 更新时间:2023-11-28 21:39:58 26 4
gpt4 key购买 nike

我正在尝试从 localhost:5000 上托管的 python 服务器向 RabbitMQ 服务器发送消息(使用 RabbitMQ 的 docker 镜像),但出现以下错误:

socket.gaierror gaierror: [Errno -2] Name or service not known

我正在使用命令运行 RabbitMQ 的 docker 镜像,其中“rabbithost”是我使用的主机名:

sudo docker run -d --hostname rabbithost --name rabbitmq -p 15672:15672 -p 5672:5672 -p 5671:5671 rabbitmq:3-management

这是给出错误的 python 代码:

def send_to_queue(message):
credentials = pika.PlainCredentials('guest', 'guest')
parameters = pika.ConnectionParameters('rabbithost', 5672, '/', credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='', routing_key='hello',body=message)
connection.close()
return "Message Sent! "

错误在行:

connection = pika.BlockingConnection(parameters)

主要是因为parameters参数。我无法找到此错误的确切解决方案。

最佳答案

python代码在哪里运行?在本地主机上?如果是,那么您需要将 rabbithost 更改为 127.0.0.1 或在 /etc/hosts 中为 127.0 创建一个主机条目。 0.1 兔子主机

关于python - 套接字.gaierror gaierror : [Errno -2] Name or service not known - pika rabbitMQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46187647/

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