Opened 5 years ago

Last modified 5 years ago

#7962 defect new

names.client doesn't work on Windows

Reported by: Gareth Coles Owned by:
Priority: normal Milestone:
Component: names Keywords: dns
Cc: Branch:
Author:

Description

When running the following code..

import twisted.names.client
from twisted.internet import reactor

def do_lookup(domain):
    d = twisted.names.client.getHostByName(domain)
    d.addBoth(lookup_done)

def lookup_done(result):
    print 'result:', result
    reactor.stop()

domain = 'twistedmatrix.com'
reactor.callLater(0, do_lookup, domain)
reactor.run()

On Linux, I correctly get the IP address of twistedmatrix as output.

On Windows, I get the following:

result: [Failure instance: Traceback (failure with no frames): <class 'twisted.names.error.ResolverError'>: Stuck at response without answers or delegation]

I've tried setting various values for each parameter to getHostByName(), as well as attempting to use createResolver() with Google's DNS servers, but I always get the above error.

I also noticed that someone encountered this problem on StackOverflow, but was unable to find a ticket here.

Change History (2)

comment:1 Changed 5 years ago by Gareth Coles

Ticket's backwards; encountered the problem, then found the above code on SO. You guys get the idea, I'm sure.

comment:2 Changed 5 years ago by Chris Shucksmith

Likewise I found twisted.names.client.getHostByName() not working on a firewalled Windows desktop. It was due to UDP traffic to the root DNS servers being firewalled.

I came up with a workaround involving retrieving the local Windows DNS settings and manually installing a resolver to use them. I've put the workaround on the stack overflow ticket above and posted it here: https://gist.github.com/shuckc/af7490e1c4a2652ca740

I am not sure this technique is robust enough to use in core but it seems worth considering.

There is an additional problem with createResolver() ignoring the "servers" argument on win32.

Note: See TracTickets for help on using tickets.