Search code examples
pythondnsdnspython

Why is dnspython giving me this error?


Here is my simple code:

    print host
    for rdata in dns.resolver.query(host, 'CNAME') :
      prod_host = str(rdata.target)

I'm pulling host out of a file. When I run this, I get the following:

"www.maizena.es"
Traceback (most recent call last):
  File "lexparse.py", line 488, in <module>
dfs(rules_tree)
  File "lexparse.py", line 486, in dfs
dfs(child)
  File "lexparse.py", line 486, in dfs
dfs(child)
  File "lexparse.py", line 471, in dfs
for rdata in dns.resolver.query(host, 'CNAME') :
  File "build/bdist.macosx-10.11-intel/egg/dns/resolver.py", line 1132, in query
  File "build/bdist.macosx-10.11-intel/egg/dns/resolver.py", line 1051, in query
dns.resolver.NXDOMAIN: None of DNS query names exist: \"www.maizena.es\"., \"www.maizena.es\".masked.domain.com., \"www.maizena.es\".domain.com., \"www.maizena.es\".netarch.domain.com., \"www.maizena.es\".fr.adsvc., \"www.maizena.es\".domainlab.com.

What's odd is that when I run a test in the python repl it seems to work as expected:

bos-mpqpu:config_parse rabdelaz$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dns.resolver
>>> for rdata in dns.resolver.query("www.maizena.es", 'CNAME') :
...     prod_host = str(rdata.target)
... 
>>> prod_host
'sana.kona.unilever.com.edgekey.net.'

Furthermore, the dns resolution from my command line works just fine:

$ dig www.maizena.es

; <<>> DiG 9.8.3-P1 <<>> www.maizena.es
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15148
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.maizena.es.            IN  A

;; ANSWER SECTION:
www.maizena.es.     138 IN  CNAME   sana.kona.unilever.com.edgekey.net.
sana.kona.unilever.com.edgekey.net. 154 IN CNAME e10923.x.akamaiedge.net.
e10923.x.akamaiedge.net. 20 IN  A   96.6.167.93

;; Query time: 73 msec
;; SERVER: 172.27.112.15#53(172.27.112.15)
;; WHEN: Tue Jul 25 11:24:11 2017
;; MSG SIZE  rcvd: 130

Any insight appreciated.


Solution

  • Issue here is the string actually has double quotes embedded in it. I need to strip those out.

    Notice: \"www.maizena.es\" in the error message.

    I modified my script like this:

        print repr(host)
        for rdata in dns.resolver.query(host[1:-1], 'CNAME') :
          prod_host = str(rdata.target)
    

    using print repr() helped identify the extraneous double quotes.