I saw this exception when I was testing pika
It works when I was using only defaults. However it threw an exception when I added credentials in the connection parameters.
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()
It gave me this error:
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
Can any help me ? Thanks.
That error normally means that either your credentials are wrong, or that the user you created doesn't have access to the exchange / queue you're trying to access. When creating the user, make sure to give access to the resources you're going to be using (or, if it's just for testing, to everything the same way the 'guest' account has). You can do this via the management plugin or the command line.
This post has a good sample on how to set the different permissions using the management plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With