如何使用python解决Rabbitmq中的使用者错误

如何使用python解决Rabbitmq中的使用者错误,rabbitmq,Rabbitmq,当我使用python在rabbitmq中为headersExchange运行Consumer.py时,会出现如下错误 我在下面提到了消费者和发布程序 Traceback (most recent call last): File "headersConsumer.py", line 32, in <module> main() File "headersConsumer.py", line 14, in main cha

当我使用python在rabbitmq中为headersExchange运行Consumer.py时,会出现如下错误 我在下面提到了消费者和发布程序

Traceback (most recent call last):
  File "headersConsumer.py", line 32, in <module>
    main()
  File "headersConsumer.py", line 14, in main
    channel.exchange_declare(exchange = 'headers_logs',exchange_type='headers',durable=True)
  File "C:\Python38\lib\site-packages\pika\adapters\blocking_connection.py", line 2387, in 
exchange_declare
    self._flush_output(declare_ok_result.is_ready)
  File "C:\Python38\lib\site-packages\pika\adapters\blocking_connection.py", line 1339, in 
_flush_output
    raise self._closing_reason  # pylint: disable=E0702
pika.exceptions.ChannelClosedByBroker: (406, "PRECONDITION_FAILED 
- inequivalent arg 'type' for exchange 'headers_logs' in vhost '/': received 'headers' but 
current is 'fanout'")
我写过这样的出版程序

import pika
import sys

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

channel.exchange_declare(exchange='headers_logs',exchange_type='headers')

message = ' '.join(sys.argv[1:]) or "Hello World!"
channel.basic_publish((exchange='headers_logs',routing_key="",body=message,properties=pika.BasicProperties(
        delivery_mode = 2, # make message persistent
        headers = {'key1':'one', 'key2': 'three'}
    ))

print(" [x] Sent %r" % message)
connection.close()

我不理解此错误,请任何人建议此错误

前提条件_失败
表示您使用一组参数声明了一个交换,然后您尝试使用不同的参数创建相同的队列名称

就你而言:

headers_logs' in vhost '/': received 'headers' but 
current is 'fanout'")
因此,您正在尝试将exchange类型从扇出更改为标头

Se以获取更多详细信息(这是针对队列的,但交换以相同的方式工作)

在使用队列之前,必须先声明它。声明队列 如果它不存在,将导致创建它。这个 如果队列已存在且 其属性与声明中的属性相同。当 现有队列属性与声明中的属性不同 将出现代码为406(前提条件_失败)的通道级异常 提高

headers_logs' in vhost '/': received 'headers' but 
current is 'fanout'")