payload = {
"items": [
{
"channel": "0001010",
"formats": {
"http-stream": {
"content-bin": base64.b64encode(b"hello world").decode("ascii")
}
},
}
]
}
I have the above which works well when used with http /publish, please ignore the b"hello world" part, it’s just a placeholder for the data I am streaming.
import base64
import tnetstring
import zmq
context = zmq.Context()
socket = context.socket(zmq.PUSH)
socket.connect("tcp://localhost:5560")
def encode_values(obj):
if isinstance(obj, dict):
return {
k.encode("utf-8") if isinstance(k, str) else k: encode_values(v)
for k, v in obj.items()
}
elif isinstance(obj, list):
return [encode_values(item) for item in obj]
elif isinstance(obj, str):
return obj.encode("utf-8")
else:
return obj
payload = {
"items": [
{
"channel": "0001010",
"formats": {
"http-stream": {
"content-bin": base64.b64encode(b"hello world").decode("ascii")
}
},
}
]
}
tnet_message = tnetstring.dumps(encode_values(payload))
socket.send(tnet_message)
print("Sent message:", tnet_message)
socket.close()
context.term()
The above is the code but I get the below error
[DEBUG] 2025-05-25 05:02:49.046 [handler] IN pull: { "items": [ { "formats": { "http-stream": { "content-bin": "aGVsbG8gd29ybGQ=" } }, "channel": "0001010" } ] }
[WARN] 2025-05-25 05:02:49.046 [handler] IN pull: received message with invalid format: publish item object does not contain 'channel', skipping
It means there’s something I am not doing well. Please, I need help with it, thank you.