DEV Community

Discussion on: SignalR core python client: A simple Chat Hub Client

Collapse
 
mandrewcito profile image
Andrés Baamonde Lozano

Yes, you can, 'print' is only the callback function. If you create a function like this:

import uuid
import json
def save_message(msg):
    with open(f"{uuid.uuid4()}.json",'w+') as fh:
        fh.write(json.dumps(msg))
Enter fullscreen mode Exit fullscreen mode

Then you only need to replace 'print' on the callback register function:

hub_connection.on("ReceiveMessage", save_message)
Enter fullscreen mode Exit fullscreen mode

This changes will save data passed trhoung signalr

Collapse
 
samy0392 profile image
Samer Abbas

Thank you so much!

Collapse
 
ddua123 profile image
ddua123

Getting this error- raise TypeError(f'Object of type {o.class.name} '
f'is not JSON serializable')
E TypeError: Object of type WebSocketService is not JSON serializable
Please let me know how to correct it?