首页 > 解决方案 > AttributeError:模块'pika'在rabbitmq中没有属性'BlockingConnection'错误

问题描述

最近我尝试使用 pika 库将队列作为 rabitmq ( rabbitmq_tutorials_partOne ) 的文档,我输入了以下代码:

import pika

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()

channel.queue_declare(queue='hello')

channel.basic_publish(exchange='',
                  routing_key='hello',
                  body='Hello World!')
print(" [x] Sent 'Hello World!'")

connection.close()

但是我有这个错误:

AttributeError: module 'pika' has no attribute 'BlockingConnection'

我安装的鼠兔版本是:0.12.0。我用这个命令安装 pika : pip3 install pika。我无法意识到我的问题是什么。有没有什么办法解决这一问题?

标签: pythonpython-3.xrabbitmqqueuepika

解决方案


推荐阅读