-
-
Notifications
You must be signed in to change notification settings - Fork 616
Open
Labels
Description
Describe the bug
After updating to 5.14.0 seems I am not able to send to clients already prepared bytes anymore. It seems like this PR is causing the issue -> #1502
To Reproduce
- Somewhere in my code I have next:
async def set_client(self, sid, data): await self.emit( event='set', data=serialize_to_message_pack_as( self.client_schemas['set'], data, ), # <- this function produces byte object, example: b'\xde\x00\x01\xa5tasks\x90' to=sid, )
- When I trigger this function in test suite/local run I get next error:
...
File "/.../.venv/lib/python3.12/site-packages/socketio/async_redis_manager.py", line 118, in _publish
self.channel, json.dumps(data))
...
TypeError: Object of type bytes is not JSON serializable
Expected behavior
A should be able to send data as bytes to clients, so I can parse as bytes on clients as well according to docs: https://python-socketio.readthedocs.io/en/latest/server.html#emitting-events-to-clients.
On the 5.13.0 all behavior works, 3k tests are all green, I can send and receive bytes.
Logs
Traceback (most recent call last):
File "/.../.venv/lib/python3.12/site-packages/socketio/async_server.py", line 612, in _handle_event_internal
r = await server._trigger_event(data[0], namespace, sid, *data[1:])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.../.venv/lib/python3.12/site-packages/socketio/async_server.py", line 662, in _trigger_event
return await handler.trigger_event(event, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.../.venv/lib/python3.12/site-packages/socketio/async_namespace.py", line 38, in trigger_event
ret = await handler(*args)
^^^^^^^^^^^^^^^^^^^^
File "/.../dashboard.py", line 31, in on_mount_dashboard
await self.set_client(sid, {'tasks': presentable_tasks})
File "/.../base_namespace.py", line 255, in set_client
await self.emit(
File "/.../.venv/lib/python3.12/site-packages/socketio/async_namespace.py", line 70, in emit
return await self.server.emit(event, data=data, to=to, room=room,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.../.venv/lib/python3.12/site-packages/socketio/async_server.py", line 178, in emit
await self.manager.emit(event, data, namespace, room=room,
File "/.../.venv/lib/python3.12/site-packages/socketio/async_pubsub_manager.py", line 72, in emit
await self._publish(message) # notify other hosts
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.../.venv/lib/python3.12/site-packages/socketio/async_redis_manager.py", line 118, in _publish
self.channel, json.dumps(data))
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/json/encoder.py", line 200, in encode
chunks = self.iterencode(o, _one_shot=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/json/encoder.py", line 258, in iterencode
return _iterencode(o, 0)
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/json/encoder.py", line 180, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable
Received event "set" [/client]
2025-10-13 17:31:10 INFO Received event "set" [/client]
Engine.IO connection dropped
2025-10-13 17:31:13 INFO Engine.IO connection dropped
2025-10-13 17:31:13 INFO Disconnected :(
2025-10-13 17:31:13 DEBUG Connection closed on namespace=/client: x7xcl6Rx6KbgZ-kNAAAB
Am I doing something wrong here?