2017-09-13 64 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

相關問題