[Twisted-Python] Twisted.Names assistance with auth and additional sections
Hey all, I have a client I have written using twisted.names that will send a DNS request. Here is the gist of the relevant code: (tfp, tfile) = tempfile.mkstemp() os.write(tfp, 'nameserver %s' % ip) os.close(tfp) resolver = client.createResolver(resolvconf=tfile) deferred = resolver.lookupAddress(somevalue) deferred.addCallback(resultHandler) hacky way to set the IP, but I am having issues with passing in the "servers" list I don't want to troubleshoot until I figure out this problem. Anyways, as you can see, this code calls the lookupAddress method for the name I want. The problem I am having is it is only returning the answer section of the response. I need the additional and authority sections as well (and I know for sure those sections exist in the response). I have looked at the docs and the code, and I don't know what I am missing. I am sure it's something silly, but I am missing it right now. So long question short, what do I need to change in my code so I can get the additional sections and authority sections in the response so I can get to those values? Thanks, Sean
On Tue, 20 Mar 2007 14:27:26 -0700, Sean Leach
Hey all,
I have a client I have written using twisted.names that will send a DNS request. Here is the gist of the relevant code:
(tfp, tfile) = tempfile.mkstemp() os.write(tfp, 'nameserver %s' % ip) os.close(tfp) resolver = client.createResolver(resolvconf=tfile) deferred = resolver.lookupAddress(somevalue) deferred.addCallback(resultHandler)
hacky way to set the IP, but I am having issues with passing in the "servers" list I don't want to troubleshoot until I figure out this problem.
Anyways, as you can see, this code calls the lookupAddress method for the name I want. The problem I am having is it is only returning the answer section of the response. I need the additional and authority sections as well (and I know for sure those sections exist in the response). I have looked at the docs and the code, and I don't know what I am missing. I am sure it's something silly, but I am missing it right now.
So long question short, what do I need to change in my code so I can get the additional sections and authority sections in the response so I can get to those values?
One approach would be to use queryUDP directly instead of lookupAddress: resolver.queryUDP([dns.Query(name, dns.A, dns.IN)]) Which will give you a full message object back, including lists of answers, additional, and authority sections. Jean-Paul
Thanks Jean-Paul,
I tried changing to queryUDP, and it just sits there, never sends out
a query (watching with tcpdump). If I change it to _lookup, which it
looks like queryUDP calls, it sends the query, but like lookupAddress,
I don't get the additional and auth sections still...
What is weird, when I do this
deferred = resolver.queryUDP([Dns.Query(name, dns.IN, dns.A)])
and I try and debug why it's hanging, I put a print in the
ResolverBase.queryUDP function right at the top, and it never prints.
Regards,
Sean
On 3/20/07, Jean-Paul Calderone
On Tue, 20 Mar 2007 14:27:26 -0700, Sean Leach
wrote: Hey all,
I have a client I have written using twisted.names that will send a DNS request. Here is the gist of the relevant code:
(tfp, tfile) = tempfile.mkstemp() os.write(tfp, 'nameserver %s' % ip) os.close(tfp) resolver = client.createResolver(resolvconf=tfile) deferred = resolver.lookupAddress(somevalue) deferred.addCallback(resultHandler)
hacky way to set the IP, but I am having issues with passing in the "servers" list I don't want to troubleshoot until I figure out this problem.
Anyways, as you can see, this code calls the lookupAddress method for the name I want. The problem I am having is it is only returning the answer section of the response. I need the additional and authority sections as well (and I know for sure those sections exist in the response). I have looked at the docs and the code, and I don't know what I am missing. I am sure it's something silly, but I am missing it right now.
So long question short, what do I need to change in my code so I can get the additional sections and authority sections in the response so I can get to those values?
One approach would be to use queryUDP directly instead of lookupAddress:
resolver.queryUDP([dns.Query(name, dns.A, dns.IN)])
Which will give you a full message object back, including lists of answers, additional, and authority sections.
Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
On Tue, 20 Mar 2007 16:13:14 -0700, Sean Leach
Thanks Jean-Paul,
I tried changing to queryUDP, and it just sits there, never sends out a query (watching with tcpdump). If I change it to _lookup, which it looks like queryUDP calls, it sends the query, but like lookupAddress, I don't get the additional and auth sections still...
What is weird, when I do this
deferred = resolver.queryUDP([Dns.Query(name, dns.IN, dns.A)])
and I try and debug why it's hanging, I put a print in the ResolverBase.queryUDP function right at the top, and it never prints.
The factoring here is a little weird. Try creating a t.names.client.Resolver explicitly (just instantiate it with a servers list or a resolv.conf filename) and calling queryUDP on it (unless you were doing this already). The createResolver function does some other stuff which might be getting in the way here, either of functioning or debugging. Here's an example (using t/conch/stdio.py):
from twisted.names import dns, client r = client.Resolver(servers=[('198.41.0.4', 53)]) d = r.queryUDP([dns.Query('google.com', dns.IN, dns.A)]) d
> d.result d.result.authority [ ] d.result.additional [ ] d.result.answers []
Hope this helps things, Jean-Paul
Sweet! That was it. Explicitly creating the Resolver worked like a
charm (don't ask me why :) ). Thanks!
On 3/20/07, Jean-Paul Calderone
On Tue, 20 Mar 2007 16:13:14 -0700, Sean Leach
wrote: Thanks Jean-Paul,
I tried changing to queryUDP, and it just sits there, never sends out a query (watching with tcpdump). If I change it to _lookup, which it looks like queryUDP calls, it sends the query, but like lookupAddress, I don't get the additional and auth sections still...
What is weird, when I do this
deferred = resolver.queryUDP([Dns.Query(name, dns.IN, dns.A)])
and I try and debug why it's hanging, I put a print in the ResolverBase.queryUDP function right at the top, and it never prints.
The factoring here is a little weird. Try creating a t.names.client.Resolver explicitly (just instantiate it with a servers list or a resolv.conf filename) and calling queryUDP on it (unless you were doing this already). The createResolver function does some other stuff which might be getting in the way here, either of functioning or debugging.
Here's an example (using t/conch/stdio.py):
from twisted.names import dns, client r = client.Resolver(servers=[('198.41.0.4', 53)]) d = r.queryUDP([dns.Query('google.com', dns.IN, dns.A)]) d
> d.result d.result.authority [ ] d.result.additional [ ] d.result.answers [] Hope this helps things,
Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Ok...ignore my last post, jumped the gun, the additional and authority
still don't exist in the result object. In addition, I tried your
example to make sure I wasn't crazy, and it doesn't return any result
data. I know it's not a network issue or anything silly as I can
query a.root fine with dig and get the results. Here is the session:
$ cat test.py
#!/usr/bin/python2.4
import time
from twisted.names import dns, client, _version
print _version.version
def errorHandler(error):
print str(error)
r = client.Resolver(servers=[('198.41.0.4', 53)])
d = r.queryUDP([dns.Query('google.com', dns.IN,
dns.A)]).addErrback(errorHandler)
time.sleep(5) ## give it a time for shitz and giggles
print d
print d.result
$ ./test.py
[twisted.names, version 0.4.0]
Sweet! That was it. Explicitly creating the Resolver worked like a charm (don't ask me why :) ). Thanks!
On 3/20/07, Jean-Paul Calderone
wrote: On Tue, 20 Mar 2007 16:13:14 -0700, Sean Leach
wrote: Thanks Jean-Paul,
I tried changing to queryUDP, and it just sits there, never sends out a query (watching with tcpdump). If I change it to _lookup, which it looks like queryUDP calls, it sends the query, but like lookupAddress, I don't get the additional and auth sections still...
What is weird, when I do this
deferred = resolver.queryUDP([Dns.Query(name, dns.IN, dns.A)])
and I try and debug why it's hanging, I put a print in the ResolverBase.queryUDP function right at the top, and it never prints.
The factoring here is a little weird. Try creating a t.names.client.Resolver explicitly (just instantiate it with a servers list or a resolv.conf filename) and calling queryUDP on it (unless you were doing this already). The createResolver function does some other stuff which might be getting in the way here, either of functioning or debugging.
Here's an example (using t/conch/stdio.py):
from twisted.names import dns, client r = client.Resolver(servers=[('198.41.0.4', 53)]) d = r.queryUDP([dns.Query('google.com', dns.IN, dns.A)]) d
> d.result d.result.authority [ ] d.result.additional [ ] d.result.answers [] Hope this helps things,
Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Quoting Sean Leach
Ok...ignore my last post, jumped the gun, the additional and authority still don't exist in the result object. In addition, I tried your example to make sure I wasn't crazy, and it doesn't return any result data. I know it's not a network issue or anything silly as I can query a.root fine with dig and get the results. Here is the session:
$ cat test.py #!/usr/bin/python2.4 import time from twisted.names import dns, client, _version print _version.version def errorHandler(error): print str(error) r = client.Resolver(servers=[('198.41.0.4', 53)]) d = r.queryUDP([dns.Query('google.com', dns.IN, dns.A)]).addErrback(errorHandler) time.sleep(5) ## give it a time for shitz and giggles print d print d.result
I *think* you're missing something about Twisted. You should start the reactor to have something, and *never* use time.sleep inside a Twisted program. You could start with reading the documentation here: http://twistedmatrix.com/projects/core/documentation/howto/async.html. -- Thomas
Yes - I know, this was a small example program to show the problem I
was seeing. And I have read over all of the documentation, including
the Twisted.names source.
On 3/21/07, Thomas Hervé
Quoting Sean Leach
: Ok...ignore my last post, jumped the gun, the additional and authority still don't exist in the result object. In addition, I tried your example to make sure I wasn't crazy, and it doesn't return any result data. I know it's not a network issue or anything silly as I can query a.root fine with dig and get the results. Here is the session:
$ cat test.py #!/usr/bin/python2.4 import time from twisted.names import dns, client, _version print _version.version def errorHandler(error): print str(error) r = client.Resolver(servers=[('198.41.0.4', 53)]) d = r.queryUDP([dns.Query('google.com', dns.IN, dns.A)]).addErrback(errorHandler) time.sleep(5) ## give it a time for shitz and giggles print d print d.result
I *think* you're missing something about Twisted. You should start the reactor to have something, and *never* use time.sleep inside a Twisted program.
You could start with reading the documentation here: http://twistedmatrix.com/projects/core/documentation/howto/async.html.
-- Thomas
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
On Wed, 2007-03-21 at 05:31 -0700, Sean Leach wrote:
Yes - I know, this was a small example program to show the problem I was seeing. And I have read over all of the documentation, including the Twisted.names source.
That example program is always going to fail without reactor.run(), though, so it doesn't really serve its purpose if you've found a real bug.
On Wed, 21 Mar 2007 05:31:08 -0700, Sean Leach
Yes - I know, this was a small example program to show the problem I was seeing. And I have read over all of the documentation, including the Twisted.names source.
The example I gave might have been a bit confusing. I was using a shell that has the reactor running already, so I didn't need to start it. The equivalent as a normal Twisted program would be something like: #!/usr/bin/python2.4 import time from twisted.names import dns, client, _version from twisted.internet import reactor def errorHandler(error): print str(error) def gotMessage(message): print message.answers print message.additional print message.authority r = client.Resolver(servers=[('198.41.0.4', 53)]) d = r.queryUDP([ dns.Query('google.com', dns.IN, dns.A)]) d.addErrback(errorHandler) d.addCallback(gotMessage) reactor.run() Jean-Paul
participants (4)
-
Itamar Shtull-Trauring
-
Jean-Paul Calderone
-
Sean Leach
-
Thomas Hervé