Can I have some examples of dnspython for DOH and DOT

1,026 views
Skip to first unread message

tech wizard

unread,
Feb 25, 2021, 2:40:04 AM2/25/21
to dnspython-users
I need some python3 examples for testing the servers, but its not there in docs. So can Someone help me out.

Bob Halley

unread,
Feb 25, 2021, 12:15:09 PM2/25/21
to dnspython-users
DoH example

DoT example:

import dns.message
import dns.name
import dns.query

qname = dns.name.from_text('dns.google.')
q = dns.message.make_query(qname, dns.rdatatype.A)
response = dns.query.tls(q, '8.8.8.8')
print(response)

tech wizard

unread,
Feb 26, 2021, 12:41:26 AM2/26/21
to dnspython-users
Thanks a lot.

tech wizard

unread,
Mar 9, 2021, 5:06:05 AM3/9/21
to dnspython-users
Hey

I have a new issue while running the DoH Example inside docker

Traceback (most recent call last):
  File "temp.py", line 42, in <module>
    main()
  File "temp.py", line 21, in main
    r = dns.query.https(q, where, session=session)
  File "/usr/local/lib/python3.8/dist-packages/dns/query.py", line 278, in https
    raise NoDOH  # pragma: no cover
dns.query.NoDOH: DNS over HTTPS (DOH) was requested but the requests module is not
    available.

But I have requests module installed and up-to-date.
How can I fix this

Bob Halley

unread,
Mar 9, 2021, 7:18:25 AM3/9/21
to dnspython-users
That exception means that one of the requirements could not be imported.  dnspython needs both requests and requests-toolbelt.  Maybe you're missing the latter?

If you're installing dnspython with pip, you can say

pip install dnspython[doh]

to install dnspython and all the requirements for DoH.

tech wizard

unread,
Mar 9, 2021, 7:43:02 AM3/9/21
to dnspython-users
oh yah I forget about the additional release
do we have any additional for DoT also ?

Bob Halley

unread,
Mar 9, 2021, 10:38:59 AM3/9/21
to dnspython-users
DoT uses python's ssl module, so no extra requirements.

tech wizard

unread,
Mar 9, 2021, 8:45:57 PM3/9/21
to dnspython-users
Okk, Thanks a lot.
It worked actually
Reply all
Reply to author
Forward
0 new messages