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

Pra*_*ngh 2 python sockets rabbitmq pika docker

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

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

我正在使用命令'Rabbithost'是我正在使用的主机名运行RabbitMQ的docker镜像:

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!  "
Run Code Online (Sandbox Code Playgroud)

错误在第:

连接= pika.BlockingConnection(参数)

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

Tar*_*ani 5

python代码在哪里运行?在本地主机上?如果是的话,那么你要么需要改变rabbithost,以127.0.0.1或使主机条目/etc/hosts为127.0.0.1 rabbithost