From 54adcc01576976a89ad177777de7926900227e76 Mon Sep 17 00:00:00 2001 From: dly2424 <46138781+dly2424@users.noreply.github.com> Date: Tue, 26 Apr 2022 17:32:06 -0400 Subject: [PATCH] Fixed another rare migration bug from Alta's end. After ~50 days consecutively of running a bot with py-tale, it crashed with this error: `{'id': 26, 'event': 'response', 'key': 'GET /ws/migrate', 'content': '{"message":"IDX20803: Unable to obtain configuration from: \'System.String\'.","error_code":"None"}', 'responseCode': 403}` I believe this is either due to a bug or crash on Alta's end. In this new version of py-tale I've created a generic check to ensure the response code is `200` and if not, perform a manual migration just like it would if the response took too long from the last update of py-tale. --- py_tale.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/py_tale.py b/py_tale.py index b9a6b5c..3ddc0b8 100644 --- a/py_tale.py +++ b/py_tale.py @@ -484,7 +484,14 @@ async def run_ws(self): var = json.loads(var) #Implement unsubscribing on old websocket? Maybe next verison, I don't think it's an issue. if "key" in var: if var["key"] == "GET /ws/migrate": - self.migrate_token = var["content"] + try: + if int(var["responseCode"]) == 200: + self.migrate_token = var["content"] + else: + print(Fore.RED + "Error in migrate response: Ignoring new key. I will perform a manual migrate instead. (non-200 response code)", end=Style.RESET_ALL + "\n") + except Exception as e: + if self.debug: + print(Fore.RED + f"Error in migrate response: Ignoring new key. I will perform a manual migrate instead. ({e})", end=Style.RESET_ALL + "\n") if self.ws is websocket: #Only listen to subscriptions if the websocket is the latest websocket. Safety check for preventing double subscriptions if migrate fails while two websockets are open. if "id" in var and "event" in var: if var["event"] == "response" and int(var["id"]) in self.websocket_responses: