From 330a034329d644e31a853f59d18ec6bed7c31cab Mon Sep 17 00:00:00 2001 From: missytake Date: Wed, 13 Dec 2023 14:23:05 +0100 Subject: [PATCH] DNS: ignore DNS resolvers which don't give us JSON --- cmdeploy/src/cmdeploy/dns.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmdeploy/src/cmdeploy/dns.py b/cmdeploy/src/cmdeploy/dns.py index d470cdeb..f610c067 100644 --- a/cmdeploy/src/cmdeploy/dns.py +++ b/cmdeploy/src/cmdeploy/dns.py @@ -1,5 +1,6 @@ import requests from ipaddress import ip_address +from json.decoder import JSONDecodeError resolvers = [ "https://dns.nextdns.io/dns-query", @@ -31,7 +32,11 @@ class DNS: headers={"accept": "application/dns-json"}, ) - j = r.json() + try: + j = r.json() + except JSONDecodeError: + # ignore DNS resolvers which don't give us JSON + continue if "Answer" in j: for answer in j["Answer"]: if answer["type"] == dns_types[typ]: @@ -47,7 +52,11 @@ class DNS: headers={"accept": "application/dns-json"}, ) - j = r.json() + try: + j = r.json() + except JSONDecodeError: + # ignore DNS resolvers which don't give us JSON + continue if "Answer" in j: result = (0, None) for answer in j["Answer"]: