Python BOT keeps disconnecting, even with PONGs

Try putting it into a buffer, and only continue when you are certain it has a full message.