[Twisted-Python] Trouble with Record_TXT
Nahraf34
Nahraf34 at janisary.us
Wed Jun 11 11:19:49 MDT 2014
Hi all,
I am attempting to write a small DNS server that returns custom TXT record
when I do:
dig -t TXT -p 10053 @127.0.0.1 testdomain.com
The code is as follows:
----------
#!/usr/bin/python
from twisted.internet import reactor
from twisted.names import client, dns, server
class DynamicResolver(object):
def query(self, query, timeout=None):
name = query.name.name
# answer = dns.RRHeader(
# name = name,
# payload = dns.Record_A(address=b'1.2.3.4'))
answer = dns.RRHeader(
name = name,
payload = dns.Record_TXT(data='FirstSecond', ttl=3333))
answers = [answer]
authority = []
additional = []
return answers, authority, additional
def main():
factory = server.DNSServerFactory(
clients = [DynamicResolver()]
)
protocol = dns.DNSDatagramProtocol(controller=factory)
reactor.listenUDP(10053, protocol)
reactor.listenTCP(10053, factory)
reactor.run()
if __name__ == '__main__':
main()
----------
You will notice three lines of code are commented out. They are sample code for
an A record that work just fine. But the attempt at Record_TXT fails.
I receive the following error when I attempt to perform the dig command:
-----------
$ python servlet.py
Unhandled Error
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/twisted/names/dns.py", line 2326, in datagramReceived
self.controller.messageReceived(m, self, addr)
File "/usr/local/lib/python2.7/dist-packages/twisted/names/server.py", line 192, in messageReceived
self.handleQuery(message, proto, address)
File "/usr/local/lib/python2.7/dist-packages/twisted/names/server.py", line 136, in handleQuery
return self.resolver.query(query).addCallback(
File "/usr/local/lib/python2.7/dist-packages/twisted/names/common.py", line 73, in query
return defer.maybeDeferred(method, query.name.name, timeout)
--- <exception caught here> ---
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 139, in maybeDeferred
result = f(*args, **kw)
File "/usr/local/lib/python2.7/dist-packages/twisted/names/common.py", line 81, in lookupAddress
return self._lookup(name, dns.IN, dns.A, timeout)
File "/usr/local/lib/python2.7/dist-packages/twisted/names/resolve.py", line 79, in _lookup
d = self.resolvers[0].query(q, timeout)
File "servlet.py", line 16, in query
payload = dns.Record_TXT(data='FirstSecond', ttl=3333))
File "/usr/local/lib/python2.7/dist-packages/twisted/names/dns.py", line 867, in __init__
assert (payload is None) or isinstance(payload, UnknownRecord) or (payload.TYPE == type)
exceptions.AssertionError:
-----------
I'm a little confused, because I followed the documentation as referenced here:
http://twistedmatrix.com/documents/current/api/twisted.names.dns.Record_TXT.html
Any ideas what this error means and why it is happening?
Thank you,
Nahraf
More information about the Twisted-Python
mailing list