3

我在测试 pika 时看到了这个异常

当我只使用默认值时它可以工作。但是,当我在连接参数中添加凭据时,它引发了异常。

import pika
credentials = pika.PlainCredentials('foo', 'bar')
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost', credentials=credentials))
channel = connection.channel()
channel.queue_declare(queue='device_presence_info')
print ' [*] Waiting for messages. To exit press CTRL+C'

def callback(ch, method, properties, body):
    print " [x] Received %s" % body

channel.basic_consume(callback,
                  queue='device_presence_info',
                  no_ack=True)

channel.start_consuming()

它给了我这个错误:

ubuntu@SDNS:~/lang/python/pika$ python receive.py
Traceback (most recent call last):
  File "receive.py", line 12, in <module>
    connection = pika.BlockingConnection(pika.ConnectionParameters(host='54.241.122.167', credentials=credentials))
  File "/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py", line 107, in __init__
    super(BlockingConnection, self).__init__(parameters, None, False)
  File "/usr/local/lib/python2.6/dist-packages/pika/adapters/base_connection.py", line 62, in __init__
    on_close_callback)
  File "/usr/local/lib/python2.6/dist-packages/pika/connection.py", line 590, in __init__
    self.connect()
  File "/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py", line 206, in connect
    if not self._adapter_connect():
  File "/usr/local/lib/python2.6/dist-packages/pika/adapters/blocking_connection.py", line 275, in _adapter_connect
    raise exceptions.AMQPConnectionError(1)
pika.exceptions.AMQPConnectionError: 1

有什么可以帮助我的吗?谢谢。

4

2 回答 2

1

该错误通常意味着您的凭据错误,或者您创建的用户无权访问您尝试访问的交换/队列。创建用户时,请确保授予对您将要使用的资源的访问权限(或者,如果只是为了测试,请以与“访客”帐户相同的方式访问所有内容)。您可以通过管理插件或命令行执行此操作。

这篇文章有一个很好的示例,介绍了如何使用管理插件设置不同的权限。

于 2013-12-05T20:42:36.053 回答
0

安装 RabbitMQ 服务器(用于 Debian/Ubuntu):

sudo apt-get install rabbitmq-server
于 2013-11-19T16:17:54.340 回答