错误提示
Traceback (most recent call last): File "consunmer.py", line 14, in <module> no_ack=True ,queue='hello' TypeError: basic_consume() got an unexpected keyword argument 'no_ack'
出错代码:
#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
def callback(ch, method, properties, body):
print(" [x] Received %r" % body)
channel.basic_consume(callback,
queue='hello',
no_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
解决方法:
只需要将
channel.basic_consume(callback, queue='hello', no_ack=True)
改为
channel.basic_consume('hello', callback, auto_ack=True)
就OK了,这是因为picka版本不同,导致参数的位置不同。