From ae5d9e9641c5b8c02f19cbd98c3eace8a2f0042a Mon Sep 17 00:00:00 2001 From: Trocotronic Date: Wed, 19 Jul 2023 23:22:10 +0200 Subject: [PATCH] Returned IDK is not JSON compliant. Moving to YAML, which is less strict. Solves #6. Signed-off-by: Trocotronic --- NativeAPI.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/NativeAPI.py b/NativeAPI.py index 1e23c43..bbbce81 100644 --- a/NativeAPI.py +++ b/NativeAPI.py @@ -8,6 +8,7 @@ import logging import credentials from vsr import VSR +import yaml logging.basicConfig(format='[%(asctime)s] [%(name)s::%(levelname)s] %(message)s', datefmt='%d/%m/%Y %H:%M:%S') @@ -169,7 +170,7 @@ def __command(self, command, post=None, data=None, dashboard=None, accept='appli if (secure_token): headers['X-MBBSecToken'] = secure_token r = self.__get_url(dashboard+command, json=post, post=data, headers=headers) - if ('json' in r.headers['Content-Type']): + if ('json' in r.headers.get('Content-Type', [])): jr = r.json() return jr return r @@ -264,10 +265,12 @@ def __get_idk(self, soup): scripts = soup.find_all('script') for script in scripts: if script.string and 'window._IDK' in script.string: + print(script.string) try: idk_txt = '{'+re.search(r'\{(.*)\}',script.string,re.M|re.S).group(1)+'}' idk_txt = re.sub(r'([\{\s,])(\w+)(:)', r'\1"\2"\3', idk_txt.replace('\'','"')) - idk = json.loads(idk_txt) + print(idk_txt) + idk = yaml.load(idk_txt, Loader=yaml.FullLoader) return idk except json.decoder.JSONDecodeError: raise VWError('Cannot find IDK credentials')