diff options
author | Bob Halley <halley@dnspython.org> | 2019-03-18 08:28:57 -0700 |
---|---|---|
committer | Bob Halley <halley@dnspython.org> | 2019-03-18 08:28:57 -0700 |
commit | d5e0ed80d88be7beb8b9a14b001741757df6bd29 (patch) | |
tree | 03cb49aefa3e74938283d4dc3d093d7c125e5187 /examples | |
parent | 268cacfd245ccd1cc59785fb84b329aab00f3ed2 (diff) | |
download | dnspython-d5e0ed80d88be7beb8b9a14b001741757df6bd29.tar.gz |
Handle the case where the NOTIFY has no answer SOA RR.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/receive_notify.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/examples/receive_notify.py b/examples/receive_notify.py index 178d73c..960e4ca 100644 --- a/examples/receive_notify.py +++ b/examples/receive_notify.py @@ -23,11 +23,16 @@ s.bind((address, port)) while True: (wire, address) = s.recvfrom(512) notify = dns.message.from_wire(wire) - soa = notify.find_rrset(notify.answer, notify.question[0].name, - dns.rdataclass.IN, dns.rdatatype.SOA) - # Do something with the SOA RR here - print('The serial number for', soa.name, 'is', soa[0].serial) + try: + soa = notify.find_rrset(notify.answer, notify.question[0].name, + dns.rdataclass.IN, dns.rdatatype.SOA) + + # Do something with the SOA RR here + print('The serial number for', soa.name, 'is', soa[0].serial) + except KeyError: + # No SOA RR in the answer section. + pass response = dns.message.make_response(notify) # type: dns.message.Message response.flags |= dns.flags.AA |