diff options
| author | Bob Halley <halley@dnspython.org> | 2020-05-28 06:03:54 -0700 |
|---|---|---|
| committer | Bob Halley <halley@dnspython.org> | 2020-05-28 06:04:04 -0700 |
| commit | 11485861f6cfcd762871f903bd68a798089f0697 (patch) | |
| tree | ec4165a4f426f73a78a3df0bfc2703482583d1be /dns/resolver.py | |
| parent | 1efbb22009ffa9bbe3aede2270a803ab76e34452 (diff) | |
| download | dnspython-11485861f6cfcd762871f903bd68a798089f0697.tar.gz | |
Fix resolve() NoAnswer problems from [Issue #488]
Diffstat (limited to 'dns/resolver.py')
| -rw-r--r-- | dns/resolver.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/dns/resolver.py b/dns/resolver.py index 2035668..f9dbd64 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -1056,7 +1056,11 @@ class Resolver(object): start = time.time() while True: (request, answer) = resolution.next_request() - if answer: + # Note we need to say "if answer is not None" and not just + # "if answer" because answer implements __len__, and python + # will call that. We want to return if we have an answer + # object, including in cases where its length is 0. + if answer is not None: # cache hit! return answer done = False @@ -1088,11 +1092,15 @@ class Resolver(object): timeout=timeout) elif protocol: continue - (answer, done) = resolution.query_result(response, None) - if answer: - return answer except Exception as ex: (_, done) = resolution.query_result(None, ex) + (answer, done) = resolution.query_result(response, None) + # Note we need to say "if answer is not None" and not just + # "if answer" because answer implements __len__, and python + # will call that. We want to return if we have an answer + # object, including in cases where its length is 0. + if answer is not None: + return answer def query(self, qname, rdtype=dns.rdatatype.A, rdclass=dns.rdataclass.IN, tcp=False, source=None, raise_on_no_answer=True, source_port=0, |
