socket.gaierror gaierror:名称或服务未知 – pika rabbitMQ

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

socket.gaierror gaierror:[Errno -2]名称或服务未知

我正在使用命令运行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! " 

错误是在线:

连接= pika.BlockingConnection(参数)

主要是因为参数的参数。 我无法find此错误的确切解决scheme。

python代码在哪里运行? 在本地主机上? 如果是,那么你需要将rabbithost更改为127.0.0.1或者在/etc/hosts127.0.0.1 rabbithost创build主机项