Why can't I connect to rabbitMQ using python?

I am learning how to use rabbitMQ. I am running the rabbit-MQ server on my MacBook and trying to connect to the python client. I followed the installation instructions here . And now I am following the tutorial shown here .

The manual says that to run this client:

#!/usr/bin/env python import pika connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) channel = connection.channel() 

However, when I do this, I get the following error when trying to establish a connection:

 WARNING:pika.adapters.base_connection:Connection to ::1:5672 failed: [Errno 61] Connection refused 

As you can see, the rabbitmq server is working fine in another window:

  % rabbitmq-server RabbitMQ 3.3.1. Copyright (C) 2007-2014 GoPivotal, Inc. ## ## Licensed under the MPL. See http://www.rabbitmq.com/ ## ## ########## Logs: /usr/local/var/log/rabbitmq/ rabbit@localhost.log ###### ## /usr/local/var/log/rabbitmq/ rabbit@localhost-sasl.log ########## Starting broker... completed with 10 plugins. % ps -ef | grep -i rabbit 973025343 37253 1 0 2:47AM ?? 0:00.00 /usr/local/Cellar/rabbitmq/3.3.1/erts-5.10.3/bin/../../erts-5.10.3/bin/epmd -daemon 973025343 37347 262 0 2:49AM ttys001 0:02.66 /usr/local/Cellar/rabbitmq/3.3.1/erts-5.10.3/bin/../../erts-5.10.3/bin/beam.smp -W w -K true -A30 -P 1048576 -- -root /usr/local/Cellar/rabbitmq/3.3.1/erts-5.10.3/bin/../.. -progname erl -- -home /Users/myUser -- -pa /usr/local/Cellar/rabbitmq/3.3.1/ebin -noshell -noinput -s rabbit boot -sname rabbit@localhost -boot /usr/local/Cellar/rabbitmq/3.3.1/releases/3.3.1/start_sasl -kernel inet_default_connect_options [{nodelay,true}] -rabbit tcp_listeners [{"127.0.0.1",5672}] -sasl errlog_type error -sasl sasl_error_logger false -rabbit error_logger {file,"/usr/local/var/log/rabbitmq/ rabbit@localhost.log "} -rabbit sasl_error_logger {file,"/usr/local/var/log/rabbitmq/ rabbit@localhost-sasl.log "} -rabbit enabled_plugins_file "/usr/local/etc/rabbitmq/enabled_plugins" -rabbit plugins_dir "/usr/local/Cellar/rabbitmq/3.3.1/plugins" -rabbit plugins_expand_dir "/usr/local/var/lib/rabbitmq/mnesia/ rabbit@localhost-plugins-expand " -os_mon start_cpu_sup false -os_mon start_disksup false -os_mon start_memsup false -mnesia dir "/usr/local/var/lib/rabbitmq/mnesia/ rabbit@localhost " -kernel inet_dist_listen_min 25672 -kernel inet_dist_listen_max 25672 

How to establish this connection? What is the problem?

+6
source share
1 answer

The client tries to connect using IPv6 localhost ( ::1:5672 ), and the server listens to IPv4 localhost ( {"127.0.0.1",5672} ).

Try changing the client instead to connect to the local IPv4 host;

 connection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1')) 
+13
source

Source: https://habr.com/ru/post/970526/


All Articles