From: Bob Halley Date: Mon, 18 Mar 2019 15:28:57 +0000 (-0700) Subject: Handle the case where the NOTIFY has no answer SOA RR. X-Git-Tag: v2.0.0rc1~370 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5e0ed80d88be7beb8b9a14b001741757df6bd29;p=thirdparty%2Fdnspython.git Handle the case where the NOTIFY has no answer SOA RR. --- diff --git a/examples/receive_notify.py b/examples/receive_notify.py index 178d73cb..960e4cab 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