i am trying to send json data, in which i used fstring
to make the data dynamic. when pass it to the basic_publish
, i get raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type bytes is not JSON serializable
i have checked other related questions but i cant seem to work around it, i read this question
here is my code
# confuguring sender
def connect_queue():
rabbitmq = pika.BlockingConnection(
pika.ConnectionParameters("localhost")
)
return rabbitmq
def mail_pwd_sender():
conn = connect_queue()
channel = conn.channel()
channel.queue_declare(queue='mail_pwd_queue', durable=True)
channel.queue_bind(exchange='amq.direct',
queue='mail_pwd_queue')
mail_pwd_queue = channel
return mail_pwd_queue
data = {
"url":f"https://api.mailgun.net/v3/{Domain_name}/messages",
"auth" : ("api", f"{API_KEY}"),
"from_" : {"from": "mailgun@xxxxxxxxx.mailgun.org"},
"data" : {"to": [recipient_email],
"subject": subject,
"html" : html,
"recipient-variables":json.dumps(
{f{recipient_email}": {"password": f"{body}" }})}
}
send_queue = mail_pwd_sender()
send_queue.basic_publish(
exchange='amq.direct',
routing_key='mail_pwd_queue',
body=json.dumps(data),
properties=pika.BasicProperties(
delivery_mode=2
)
)