2017-09-13 145 views
0

我试图从托管在本地主机上的python服务器发送消息:5000到RabbitMQ服务器(使用Docker镜像的RabbitMQ),但我收到以下错误:socket.gaierror gaierror:[Errno -2]名称或服务未知 - pika rabbitMQ

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

我使用的,其中“rabbithost”是我使用的主机名命令运行的泊坞窗图像的RabbitMQ:

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)

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

+0

python代码在哪里运行?在本地主机上?如果是,那么你需要将'rabbithost'改为'127.0.0.1',或者在'/ etc/hosts'中为'127.0.0.1 rabbithost'改变主机条目。 –

+0

@TarunLalwani这实际上是工作的! 。感谢您的建议。 –

回答

2

python代码在哪里运行?在本地主机上?如果是,那么你需要将rabbithost更改为127.0.0.1或在/etc/hosts中为主机项输入127.0.0.1 rabbithost

相关问题