Time from JSON in websocket connection.

Hello everyone,
this is my function to synchronize my code with the server time:

async def synchronize_clock(websocket):
    await websocket.send("GET_TIME")
    response = await websocket.recv()
    print("JSON response from server:", response)
        data = json.loads(response)
        server_time = data.get("E")
        if server_time:
            server_datetime = datetime.fromisoformat(server_time)
            local_datetime = datetime.now()
            time_difference = server_datetime - local_datetime
            return time_difference.total_seconds()
            print("Error in JSON response shape")
            return 0

    except json.JSONDecodeError:
        print("Error in JSON response parsing")
        return 0

When I run it, I get this error:

JSON response from server: {"error":{"code":3,"msg":"Invalid JSON: expected value at line 1 column 1"}}

I can’t figure out how to extract the time from the JSON.
Could someone help me?

Could you provide additional details about the websocket parameter used in the synchronize_clock function?

I will ask you a more general question whose answer could help me solve the problem. Once connected to the websocket server, how do I store the server time in a variable accurate to the millisecond?

I don’t think there is a way to store the server time directly in the ‘websocket’ variable. I would suggest keeping your local clock up to date.
You can use the following endpoint to synchronize your local time with the server time (Python)
For Linux systems, consider using NTP.