From: Tim Beale Date: Thu, 17 Jan 2019 04:36:50 +0000 (+1300) Subject: dns_hub: Rename variable to avoid naming collision in exception handler X-Git-Tag: ldb-1.6.1~462 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8c248e4d903b657c209b4faedcf6dc1ddacf2fe;p=thirdparty%2Fsamba.git dns_hub: Rename variable to avoid naming collision in exception handler In dns_hup.py, we are both importing the socket module and declaring a variable called socket. When we try to catch a socket.error exception (defined by the module), Python thinks we're referring to the variable. As the variable has no attribute called 'error', Python throws an exception, e.g.: File "./bin/python/samba/tests/dns_forwarder_helpers/dns_hub.py", line 123, in handle except socket.error as err: AttributeError: 'socket' object has no attribute 'error' We can avoid this problem by calling the variable 'sock' instead. Signed-off-by: Tim Beale Reviewed-by: Andreas Schneider Autobuild-User(master): Andreas Schneider Autobuild-Date(master): Thu Jan 17 15:23:23 CET 2019 on sn-devel-144 --- diff --git a/python/samba/tests/dns_forwarder_helpers/dns_hub.py b/python/samba/tests/dns_forwarder_helpers/dns_hub.py index cf9beb7fa7a..067f32d0bf6 100755 --- a/python/samba/tests/dns_forwarder_helpers/dns_hub.py +++ b/python/samba/tests/dns_forwarder_helpers/dns_hub.py @@ -89,7 +89,7 @@ class DnsHandler(sserver.BaseRequestHandler): return None def handle(self): - data, socket = self.request + data, sock = self.request query = ndr.ndr_unpack(dns.name_packet, data); name = query.questions[0].name forwarder = self.forwarder(name) @@ -119,7 +119,7 @@ class DnsHandler(sserver.BaseRequestHandler): (forwarder, self.client_address, name)) try: - socket.sendto(send_packet, self.client_address) + sock.sendto(send_packet, self.client_address) except socket.error as err: print("Error sending %s to address %s for name %s: %s\n" % (forwarder, self.client_address, name, err.errno))