]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Handle the case where the NOTIFY has no answer SOA RR.
authorBob Halley <halley@dnspython.org>
Mon, 18 Mar 2019 15:28:57 +0000 (08:28 -0700)
committerBob Halley <halley@dnspython.org>
Mon, 18 Mar 2019 15:28:57 +0000 (08:28 -0700)
examples/receive_notify.py

index 178d73cb5f17ab496fe5e20d6fc1eefb818471df..960e4cab7325f770757e75a32c3d01c7d35e5a1c 100644 (file)
@@ -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