@admin I think there is some issue with the __on_close function which was causing this error. In the function definition I added 2 additional arguments a and b as shown below. This fixed the error I was getting while closing the connection using ss.ws.close().
Kindly look into it.