0

I'm using the very useful pythondns library. Unfortunately I am receiving wrong answers from it. Or should I say, I receive a noAnswer when I should have a resolution.

Here is my code:

import dns.resolver

my_resolver = dns.resolver.Resolver()

my_resolver.nameservers = ['8.8.8.8']

answer = my_resolver.query('mail1.avem-groupe.com')

Answer:

>>> answer = my_resolver.query('mail1.avem-groupe.com', 'MX')
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/dns/resolver.py", line 213, in __init__
    rdclass, rdtype)
  File "/usr/lib/python3/dist-packages/dns/message.py", line 341, in find_rrset
    raise KeyError
KeyError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/dns/resolver.py", line 223, in __init__
    dns.rdatatype.CNAME)
  File "/usr/lib/python3/dist-packages/dns/message.py", line 341, in find_rrset
    raise KeyError
KeyError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/dns/resolver.py", line 1004, in query
    raise_on_no_answer)
  File "/usr/lib/python3/dist-packages/dns/resolver.py", line 232, in __init__
    raise NoAnswer(response=response)
dns.resolver.NoAnswer: The DNS response does not contain an answer to the question: mail1.avem-groupe.com. IN MX

And the result of DIG:

$ dig mail1.avem-groupe.com

; <<>> DiG 9.11.16-2-Debian <<>> mail1.avem-groupe.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7544
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;mail1.avem-groupe.com.     IN  A

;; ANSWER SECTION:
mail1.avem-groupe.com.  3575    IN  A   31.172.163.202

;; AUTHORITY SECTION:
avem-groupe.com.    172775  IN  NS  ns-35-b.gandi.net.
avem-groupe.com.    172775  IN  NS  ns-108-c.gandi.net.
avem-groupe.com.    172775  IN  NS  ns-35-a.gandi.net.

;; Query time: 27 msec
;; SERVER: 5.132.191.104#53(5.132.191.104)
;; WHEN: Mon Mar 30 11:17:49 CEST 2020
;; MSG SIZE  rcvd: 142

I thought it was a nameserver isssue so I changed to google DNS (as per code shown above) but same result.

Any idea?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

0

Ok so it was stupid.

I was just making a 'A' request with dig instead of a 'MX'

With a 'MX' request, I have the same result as pythondns

$ dig mail1.avem-groupe.com MX

; <<>> DiG 9.11.16-2-Debian <<>> mail1.avem-groupe.com MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4276
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;mail1.avem-groupe.com.     IN  MX

;; AUTHORITY SECTION:
avem-groupe.com.    10800   IN  SOA ns1.gandi.net. hostmaster.gandi.net. 1580726993 10800 3600 604800 10800

;; Query time: 46 msec
;; SERVER: 5.132.191.104#53(5.132.191.104)
;; WHEN: Mon Mar 30 17:17:47 CEST 2020
;; MSG SIZE  rcvd: 110