How to reconnect to websocket in python

My websocket connection gets disconnected very often
websockets.exceptions.ConnectionClosedError: code = 4040 (private use), reason = Draining connection
How can I keep the websocket connection alive or reconnect automatically?

I have found a solution here on the forum for Javascript

with this as solution

reconnect: {
auto: true,
delay: 10000,
maxAttempts: 10,

How can I do this in python?

Try to search how to set those reconnect parameters in python. I don’t know the exact solution now.