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)
try:
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()
else:
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?
Thanks