Page MenuHomeMiraheze

Catch dns.resolver.NoAnswer properly inside reverse DNS check
Closed, ResolvedPublic

Description

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/dns/resolver.py", line 213, in __init__
    rdclass, rdtype)
  File "/usr/lib/python3/dist-packages/dns/message.py", line 341, in find_rrset
    raise KeyError
KeyError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/dns/resolver.py", line 223, in __init__
    dns.rdatatype.CNAME)
  File "/usr/lib/python3/dist-packages/dns/message.py", line 341, in find_rrset
    raise KeyError
KeyError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./check_reverse_dns.py", line 95, in <module>
    main()
  File "./check_reverse_dns.py", line 80, in main
    rdns_hostname = get_reverse_dnshostname(args.hostname)
  File "./check_reverse_dns.py", line 66, in get_reverse_dnshostname
    resolved_ip_addr = str(dns_resolver.query(hostname, 'A')[0])
  File "/usr/lib/python3/dist-packages/dns/resolver.py", line 1004, in query
    raise_on_no_answer)
  File "/usr/lib/python3/dist-packages/dns/resolver.py", line 232, in __init__
    raise NoAnswer(response=response)
dns.resolver.NoAnswer: The DNS response does not contain an answer to the question: museummiddelland.nl. IN A