为什么我不能使用python建立与rabbitMQ的连接? [英] Why can't I establish connection to rabbitMQ using python?

查看:62
本文介绍了为什么我不能使用python建立与rabbitMQ的连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何使用 rabbitMQ.我在 MacBook 上运行 rabbit-MQ 服务器并尝试连接 python 客户端.我按照此处的安装说明进行操作.现在我正在执行此处.

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

教程说要运行这个客户端:

The tutorial says to run this client:

#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()

但是,当我这样做时,在尝试建立连接时出现以下错误:

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

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

如您所见,rabbitmq-server 似乎在不同的窗口中运行良好:

As you can see rabbitmq-server seems to be running fine in a different 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 can I establish this connection? What is the problem?

推荐答案

客户端正在尝试使用 IPv6 localhost (::1:5672) 进行连接,而服务器正在侦听 IPv4 localhost ({"127.0.0.1",5672}).

The client is trying to connect using IPv6 localhost (::1:5672), while the server is listening to IPv4 localhost ({"127.0.0.1",5672}).

尝试更改客户端以连接到 IPv4 本地主机;

Try changing the client to connect to the IPv4 localhost instead;

connection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1'))

这篇关于为什么我不能使用python建立与rabbitMQ的连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆