使用凭据时,rabbitmq pika会抛出异常

时间:2013-08-03 02:11:36

标签: rabbitmq 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

能帮到我吗?感谢。

2 个答案:

答案 0 :(得分:1)

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

sudo apt-get install rabbitmq-server

答案 1 :(得分:1)

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

This post有一个关于如何使用管理插件设置不同权限的很好的示例。