找不到记录器“pika.adapters.blocking_connection”的处理程序

2024-04-26 12:07:20 发布

您现在位置:Python中文网/ 问答频道 /正文

类似的问题似乎都是基于使用自定义记录器,我很高兴只使用默认的/none。我的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()

Tags: importcommessagequeueloggingchannelbodyconnection