mandrewcito / signalrcore

SignalR Core python client
https://mandrewcito.github.io/signalrcore/
MIT License
115 stars 53 forks source link

{TypeError}Object of type WebSocketService is not JSON serializable #103

Open ddua123 opened 1 year ago

ddua123 commented 1 year ago

As mentioned in chats, I am trying to save the messages to a file. def save_message(msg): with open(f"{uuid.uuid4()}.json", 'w+') as fh: fh.write(json.dumps(msg))

hub_connection = HubConnectionBuilder() \ .with_url(SERVER_URL(design_id, connection_token), options={"verify_ssl": False, "skip_negotiation": False, "headers": { "Cookie": "uac.authorization={}".format(token) } }) \ .configure_logging(logging.DEBUG, socket_trace=True, handler=handler) \ .with_automatic_reconnect({ "type": "interval", "keep_alive_interval": 10, "intervals": [1, 3, 5, 6, 7, 87, 3] }).build()

    hub_connection.on_open(lambda: print("connection opened and handshake received ready to send messages"))
    hub_connection.on_close(lambda: print("connection closed"))

    hub_connection.on("ReceiveMessage", self.save_message())

Please advice how to fix it, Also if I need to close the socket connection only after receiving a particular message(for eg close socket if I received word'completed' in it). How to do that.