我在测试 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
有什么可以帮助我的吗?谢谢。