没有找到与日志记录器“pika.adapters.blocking_connection”相匹配的处理程序。

15

类似的问题好像都是围绕着使用自定义日志记录器展开的,但我很乐意只使用默认/根本不使用。我的pika python应用程序运行并接收消息,但几秒钟后就会崩溃,并显示No handlers could be found for logger "pika.adapters.blocking_connection",有什么想法吗?

import pika

credentials = pika.PlainCredentials('xxx_apphb.com', 'xxx')
parameters = pika.ConnectionParameters('bunny.cloudamqp.com', 5672, 'xxx_apphb.com', credentials)

connection = pika.BlockingConnection(parameters)
channel = connection.channel()

channel.queue_declare('messages')

def message_received(channel, method, properties, body):
    print "[x] Received %r" % (body)

channel.basic_consume(message_received, queue='messages', no_ack=True)

channel.start_consuming()

通过添加修复:

import logging
logging.basicConfig()

当我从CentOS 5升级到CentOS 6时,我遇到了类似的问题,我的rabbit服务被杀掉了。我不得不从inittab改为initctl来启动我的Python脚本,之后rabbit就没有死掉了。如果有帮助的话,我想分享一下我的评论。 - James Oravec
2个回答

30

通过添加修复:

import logging
logging.basicConfig()

当我在Python控制台中尝试使用pika时,这很有帮助。谢谢。 - Anton Danilchenko

1

应该提供交换名称,不应该保留默认值。

channel.exchange_declare(exchange='anyname')  

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接