TypeError为关键字参数队列获取了多个值

2024-04-19 18:34:34 发布

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

我被困在这个错误,我没有设法修复。我已经找到了相关的案例,但我很难将其应用到我自己的问题上。 有人能帮我理解为什么会发生这种类型错误和/或帮我找到解决方案吗?(请作为初学者回复我)

我在raspberry pi和pika 1.1.0中使用python

这是我的回溯:

  File "amqp.py", line 33, in <module>
    no_ack=True)
TypeError: basic_consume() got multiple values for keyword argument 'queue

我认为这就是相关代码:

def callback(ch, method, properties, body):

    printer.inverseOn()
    printer.println(' ' + '{:<31}'.format("TXT MESSAGE"))
    printer.inverseOff()

    printer.println(body)
    printer.feed(3)

    print("complete")
    print " [x] Received %r" % (body)

channel.basic_consume(callback,
    queue='texts',
    no_ack=True)

如果有趣的话,这就是.py的其余部分

try:
    from urllib.parse import urlparse
except ImportError:
    from urlparse import urlparse
import pika, os, sys
from Adafruit_Thermal import *

printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5)

url_str = os.environ.get('CLOUDAMQP_URL','amqp://xxxxx')
url = urlparse(url_str)
params = pika.ConnectionParameters(host=url.hostname, virtual_host=url.path[1:],
    credentials=pika.PlainCredentials(url.username, url.password))

connection = pika.BlockingConnection(params)
channel = connection.channel()
channel.queue_declare(queue='texts')

def callback(ch, method, properties, body):

    printer.inverseOn()
    printer.println(' ' + '{:<31}'.format("TXT MESSAGE"))
    printer.inverseOff()

    printer.println(body)
    printer.feed(3)

    print("complete")
    print " [x] Received %r" % (body)

channel.basic_consume(callback,
    queue='texts',
    no_ack=True)

try:

    channel.start_consuming()

except KeyboardInterrupt:

    print "Break detected"
    channel.stop_consuming()

connection.close()

sys.exit()

Tags: noimporttrueurlbasicqueuecallbackchannel