gpt4 book ai didi

rabbitmq pika 在使用凭据时抛出异常

转载 作者:行者123 更新时间:2023-12-02 01:59:21 27 4
gpt4 key购买 nike

我在测试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

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

最佳答案

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

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

关于rabbitmq pika 在使用凭据时抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18028575/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com