Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def query(self, retries=3):
exception = None
host = self.host
try:
answers = dns.resolver.query(host, "A")
if len(answers):
answer = answers[0]
host = str(answer).rstrip(".")
except Exception as e:
pass
for attempt in range(retries):
try:
connection = UDPSocketConnection((host, self.port))
querier = ServerQuerier(connection)
querier.handshake()
return querier.read_query()
except Exception as e:
exception = e
else:
raise exception