[Twisted-Python] twisted.names.error.DNSNameError on MacOsX but not on linux

Hello everyone, I wrote a twisted app using the XMPP code that works fin on linux (and windows), but on Mac I get a twisted.names.error.DNSNameError, I searched google but found nothing on this, is there a known bug with Twisted on Mac? I have Mac OS X 10.5.8, and the latest version of twisted from the website. Thank you, Gabriel

On 03:50 pm, gabriel.rossetti@arimaz.com wrote:
DNS is good at having behavior sensitive to the environment you are using it in. I'm not sure if there are any known bugs which would explain the problem you're encountering, mostly because I don't really know what problem you're encountering. ;) "twisted app using XMPP code" and "get a DNSNameError" don't say a whole lot. What API is failing? What other details can you provide? It may be a bug in Twisted, or it may be a configuration issue relating to your Mac host. Jean-Paul

exarkun@twistedmatrix.com wrote:
Hello jean-Paul, I just saw your msg, I have sent some example code. I think I nkow where this is comming from, Apple has a version of twisted installed in it's python frameworks, and it's version 2.5. I just remembered I had the same error when on version 2.5 on linux. The problem is I don't know how to cleanly resolve this problem, I would need python to use my cersion an not Apple's, but how to do this? Gabriel

Gabriel Rossetti wrote:
Here is some example code (from Twisted), this works as-is on linux but not on Mac. I tried an internal and an external XMPP server. On Mac I get this : python xmpp_client.py test@toto.com 123 2009/08/11 18:21 +0200 [-] Log opened. 2009/08/11 18:21 +0200 [-] Starting factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [-] /etc/resolv.conf changed, reparsing 2009/08/11 18:21 +0200 [-] Resolver added ('83.219.127.194', 53) to server list 2009/08/11 18:21 +0200 [-] Resolver added ('83.219.127.226', 53) to server list 2009/08/11 18:21 +0200 [-] twisted.names.dns.DNSDatagramProtocol starting on 49226 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] <__main__.XMPPClientConnector instance at 0x1003aa8> will retry in 2 seconds 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [-] Starting factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] <__main__.XMPPClientConnector instance at 0x1003aa8> will retry in 7 seconds 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [-] Starting factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] <__main__.XMPPClientConnector instance at 0x1003aa8> will retry in 14 seconds 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [-] Starting factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] <__main__.XMPPClientConnector instance at 0x1003aa8> will retry in 30 seconds 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:22 +0200 [-] Starting factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:22 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] <__main__.XMPPClientConnector instance at 0x1003aa8> will retry in 83 seconds 2009/08/11 18:22 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:23 +0200 [-] Starting factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:23 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] <__main__.XMPPClientConnector instance at 0x1003aa8> will retry in 241 seconds 2009/08/11 18:23 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> ############################################################## # -*- coding: utf-8 -*- # Copyright (c) 2001-2006 Twisted Matrix Laboratories. # See LICENSE for details. import sys from twisted.internet import reactor from twisted.names.srvconnect import SRVConnector from twisted.words.xish import domish from twisted.words.protocols.jabber import xmlstream, client, jid from twisted.python import log log.startLogging(sys.stdout) class XMPPClientConnector(SRVConnector): def __init__(self, reactor, domain, factory): SRVConnector.__init__(self, reactor, 'xmpp-client', domain, factory) def pickServer(self): host, port = SRVConnector.pickServer(self) if not self.servers and not self.orderedServers: # no SRV record, fall back.. port = 5222 return host, port class Client(object): def __init__(self, client_jid, secret): f = client.XMPPClientFactory(client_jid, secret) f.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, self.connected) f.addBootstrap(xmlstream.STREAM_END_EVENT, self.disconnected) f.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authenticated) f.addBootstrap(xmlstream.INIT_FAILED_EVENT, self.init_failed) f.addBootstrap(xmlstream.STREAM_ERROR_EVENT, self.error) connector = XMPPClientConnector(reactor, "10.204.232.117", f) connector.connect() def rawDataIn(self, buf): print "RECV: %s" % unicode(buf, 'utf-8') def rawDataOut(self, buf): print "SEND: %s" % unicode(buf, 'utf-8') def connected(self, xs): print 'Connected.' self.xmlstream = xs # Log all traffic xs.rawDataInFn = self.rawDataIn xs.rawDataOutFn = self.rawDataOut def disconnected(self, xs): print 'Disconnected.' reactor.stop() def authenticated(self, xs): print "Authenticated." presence = domish.Element((None, 'presence')) xs.send(presence) def init_failed(self, failure): print "Initialization failed." print failure self.xmlstream.sendFooter() def error(self, failure): print "error" print failure self.xmlstream.sendFooter() client_jid = jid.JID(sys.argv[1]) secret = sys.argv[2] c = Client(client_jid, secret) reactor.run()

On 04:30 pm, gabriel.rossetti@arimaz.com wrote:
Perhaps this is the problem: http://twistedmatrix.com/trac/ticket/3456 Jean-Paul

On Tue, 2009-08-11 at 18:30 +0200, Gabriel Rossetti wrote:
[..]
Apparently you modified the original example here:
This would never work properly. XMPPClientConnector is designed to do an SRV record look up on the /domain/ provided as its second argument. You pass an IP address here and that will just fail. The original example passes client_jid.host. This extracts the domain from the JID you want to connect with and then follows the procedure of first trying to find xmpp-server SRV records for that domain, and if that fails, try to connect to the host that the domain name resolves to, using the default port (5222), as outlined in RFC 3920. Note that XMPPClientConnector avoids the problems sketched in ticket #3456 that was mentioned by Jean-Paul. If you really want to connect to a specific host instead of following the above procedure, you can do this instead of the code quoted above: reactor.connectTCP("10.204.232.117", 5222, f) -- Groetjes, ralphm -- Groetjes, ralphm

Ralph Meijer wrote:
Hmmm, ok, it works on linux and windows though, but I did as you said anyways as it's still flacky on mac. Thanks, Gabriel -- Arimaz SA Ingénieur en Informatique Av. du 24 Janvier 11 Ateliers de la Ville de Renens, Atelier 5 1020 Renens, Switzerland www.arimaz.com www.mydeskfriend.com Mob: +41-(0)79-539-0069 Tel: +41-(0)21-566-7343

On 03:50 pm, gabriel.rossetti@arimaz.com wrote:
DNS is good at having behavior sensitive to the environment you are using it in. I'm not sure if there are any known bugs which would explain the problem you're encountering, mostly because I don't really know what problem you're encountering. ;) "twisted app using XMPP code" and "get a DNSNameError" don't say a whole lot. What API is failing? What other details can you provide? It may be a bug in Twisted, or it may be a configuration issue relating to your Mac host. Jean-Paul

exarkun@twistedmatrix.com wrote:
Hello jean-Paul, I just saw your msg, I have sent some example code. I think I nkow where this is comming from, Apple has a version of twisted installed in it's python frameworks, and it's version 2.5. I just remembered I had the same error when on version 2.5 on linux. The problem is I don't know how to cleanly resolve this problem, I would need python to use my cersion an not Apple's, but how to do this? Gabriel

Gabriel Rossetti wrote:
Here is some example code (from Twisted), this works as-is on linux but not on Mac. I tried an internal and an external XMPP server. On Mac I get this : python xmpp_client.py test@toto.com 123 2009/08/11 18:21 +0200 [-] Log opened. 2009/08/11 18:21 +0200 [-] Starting factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [-] /etc/resolv.conf changed, reparsing 2009/08/11 18:21 +0200 [-] Resolver added ('83.219.127.194', 53) to server list 2009/08/11 18:21 +0200 [-] Resolver added ('83.219.127.226', 53) to server list 2009/08/11 18:21 +0200 [-] twisted.names.dns.DNSDatagramProtocol starting on 49226 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] <__main__.XMPPClientConnector instance at 0x1003aa8> will retry in 2 seconds 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [-] Starting factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] <__main__.XMPPClientConnector instance at 0x1003aa8> will retry in 7 seconds 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [-] Starting factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] <__main__.XMPPClientConnector instance at 0x1003aa8> will retry in 14 seconds 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [-] Starting factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] <__main__.XMPPClientConnector instance at 0x1003aa8> will retry in 30 seconds 2009/08/11 18:21 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:22 +0200 [-] Starting factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:22 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] <__main__.XMPPClientConnector instance at 0x1003aa8> will retry in 83 seconds 2009/08/11 18:22 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:23 +0200 [-] Starting factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> 2009/08/11 18:23 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] <__main__.XMPPClientConnector instance at 0x1003aa8> will retry in 241 seconds 2009/08/11 18:23 +0200 [twisted.names.dns.DNSDatagramProtocol (UDP)] Stopping factory <twisted.words.protocols.jabber.xmlstream.XmlStreamFactory instance at 0x1003a80> ############################################################## # -*- coding: utf-8 -*- # Copyright (c) 2001-2006 Twisted Matrix Laboratories. # See LICENSE for details. import sys from twisted.internet import reactor from twisted.names.srvconnect import SRVConnector from twisted.words.xish import domish from twisted.words.protocols.jabber import xmlstream, client, jid from twisted.python import log log.startLogging(sys.stdout) class XMPPClientConnector(SRVConnector): def __init__(self, reactor, domain, factory): SRVConnector.__init__(self, reactor, 'xmpp-client', domain, factory) def pickServer(self): host, port = SRVConnector.pickServer(self) if not self.servers and not self.orderedServers: # no SRV record, fall back.. port = 5222 return host, port class Client(object): def __init__(self, client_jid, secret): f = client.XMPPClientFactory(client_jid, secret) f.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, self.connected) f.addBootstrap(xmlstream.STREAM_END_EVENT, self.disconnected) f.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authenticated) f.addBootstrap(xmlstream.INIT_FAILED_EVENT, self.init_failed) f.addBootstrap(xmlstream.STREAM_ERROR_EVENT, self.error) connector = XMPPClientConnector(reactor, "10.204.232.117", f) connector.connect() def rawDataIn(self, buf): print "RECV: %s" % unicode(buf, 'utf-8') def rawDataOut(self, buf): print "SEND: %s" % unicode(buf, 'utf-8') def connected(self, xs): print 'Connected.' self.xmlstream = xs # Log all traffic xs.rawDataInFn = self.rawDataIn xs.rawDataOutFn = self.rawDataOut def disconnected(self, xs): print 'Disconnected.' reactor.stop() def authenticated(self, xs): print "Authenticated." presence = domish.Element((None, 'presence')) xs.send(presence) def init_failed(self, failure): print "Initialization failed." print failure self.xmlstream.sendFooter() def error(self, failure): print "error" print failure self.xmlstream.sendFooter() client_jid = jid.JID(sys.argv[1]) secret = sys.argv[2] c = Client(client_jid, secret) reactor.run()

On 04:30 pm, gabriel.rossetti@arimaz.com wrote:
Perhaps this is the problem: http://twistedmatrix.com/trac/ticket/3456 Jean-Paul

On Tue, 2009-08-11 at 18:30 +0200, Gabriel Rossetti wrote:
[..]
Apparently you modified the original example here:
This would never work properly. XMPPClientConnector is designed to do an SRV record look up on the /domain/ provided as its second argument. You pass an IP address here and that will just fail. The original example passes client_jid.host. This extracts the domain from the JID you want to connect with and then follows the procedure of first trying to find xmpp-server SRV records for that domain, and if that fails, try to connect to the host that the domain name resolves to, using the default port (5222), as outlined in RFC 3920. Note that XMPPClientConnector avoids the problems sketched in ticket #3456 that was mentioned by Jean-Paul. If you really want to connect to a specific host instead of following the above procedure, you can do this instead of the code quoted above: reactor.connectTCP("10.204.232.117", 5222, f) -- Groetjes, ralphm -- Groetjes, ralphm

Ralph Meijer wrote:
Hmmm, ok, it works on linux and windows though, but I did as you said anyways as it's still flacky on mac. Thanks, Gabriel -- Arimaz SA Ingénieur en Informatique Av. du 24 Janvier 11 Ateliers de la Ville de Renens, Atelier 5 1020 Renens, Switzerland www.arimaz.com www.mydeskfriend.com Mob: +41-(0)79-539-0069 Tel: +41-(0)21-566-7343
participants (3)
-
exarkun@twistedmatrix.com
-
Gabriel Rossetti
-
Ralph Meijer