[Answered ]-Message publishing using kombu – TypeError 'str' object is not callable

2👍

Producer.exchange must be an Exchange. By default it’s Exchange(""), somehow you must have set it to a string.

👤asksol

0👍

Where ever you be passing value to ‘exchange‘ param it has to be an Exchange object.

Your code has to be:

exchange = Exchange(name='inbound') # the minimal declaration
connection = establish_connection()
producer = Producer(channel=connection,
                      exchange=exchange,
                      routing_key="apisubmit")

producer.publish(body=pl,headers={"api_access_key": "xxxx", "client_id": 4, "object_type": "location", "action": "c"})

For full list of Exchange param – docs.


I encountered the same error at queue declaration i.e.

queue = Queue(name=queue_name, exchange='host_tasks', routing_key=binding_key)
bound_queue = queue(channel) # only once bound, we can call declare(), purge(), delete() on exchange

So declared an Exchange, such thah

exchange = Exchange('host_tasks', 'direct', durable=True)
queue = Queue(name=queue_name, exchange=exchange, routing_key=binding_key)
bound_queue = queue(channel)

Don’t forget to import Exchange

Leave a comment