Python BOT keeps disconnecting, even with PONGs

That’s because this will still have the same issue as earlier. try using

buf = ""
while True:
    buf = buf + s.recv(1024).decode()
    if '\r\n' in buf:
        tmp = buf.split('\r\n')
        msg = tmp.pop(0)
        buf = '\r\n'.join(tmp)
        # parse message further

It’s getting late for me so this is kinda ugly, but I think it works.