[Twisted-Python] twisted.names.error.DNSNameError on MacOsX but not on linux
Gabriel Rossetti
gabriel.rossetti at arimaz.com
Tue Aug 11 10:30:17 MDT 2009
Gabriel Rossetti wrote:
> 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
>
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 at 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()
More information about the Twisted-Python
mailing list