catch other DNS errors that might occur and fallback to JID domain.

This commit is contained in:
Tom Nichols 2010-07-09 17:23:02 -04:00
parent 9c850f080d
commit d09cbef9a7

View File

@ -36,6 +36,7 @@ srvsupport = True
try: try:
import dns.resolver import dns.resolver
import dns.rdatatype import dns.rdatatype
import dns.exception
except ImportError: except ImportError:
srvsupport = False srvsupport = False
@ -120,6 +121,9 @@ class ClientXMPP(basexmpp, XMLStream):
answers = dns.resolver.query("_xmpp-client._tcp.%s" % self.server, dns.rdatatype.SRV) answers = dns.resolver.query("_xmpp-client._tcp.%s" % self.server, dns.rdatatype.SRV)
except dns.resolver.NXDOMAIN: except dns.resolver.NXDOMAIN:
logging.debug("No appropriate SRV record found. Using JID server name.") logging.debug("No appropriate SRV record found. Using JID server name.")
except dns.exception.DNSException:
# this could be a timeout or other DNS error. Worth retrying?
logging.exception("DNS error during SRV query for %s. Using JID server name.", self.server)
else: else:
# pick a random answer, weighted by priority # pick a random answer, weighted by priority
# there are less verbose ways of doing this (random.choice() with answer * priority), but I chose this way anyway # there are less verbose ways of doing this (random.choice() with answer * priority), but I chose this way anyway