Registry / http-networking / dnspython

dnspython

JSON →
library2.8.0pypypi✓ verified 52d ago

dnspython is a comprehensive DNS toolkit for Python, currently at version 2.8.0, supporting Python 3.10 and above. It is actively maintained and follows a regular release cadence.

http-networkingdatabase
pip install dnspython
Install & Compatibility
Where this runs
tested against v2.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.221s · 20.3MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 1.7s · import 0.194s · 21MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dns.resolver
import dns.resolver
Ensure 'dns' is not shadowed by a local module named 'dns'.
dns.query
import dns.query
Ensure 'dns' is not shadowed by a local module named 'dns'.

This script queries the A records for 'example.com' and prints each IP address.

import dns.resolver # Query for A records of 'example.com' result = dns.resolver.resolve('example.com', 'A') for ipval in result: print('IP', ipval.to_text())
dnspython --version
Debug
Known issues
breakingIn dnspython 2.0.0, the 'dns.query' module was refactored, leading to changes in function signatures and behavior. Review the changelog for detailed migration steps.
fix
Update your code to align with the new function signatures and behaviors as per the dnspython 2.0.0 release notes.
affects: >=2.0.0
gotchaAvoid naming your script 'dns.py' to prevent import conflicts with the dnspython library.
fix
Rename your script to a different name to prevent import conflicts.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'dns'
The `dnspython` package, which provides the `dns` module, is not installed in the Python environment, or the environment where it's installed is not the one being used.
fix
Install the `dnspython` package using pip: `pip install dnspython`
ModuleNotFoundError: No module named 'dnspython'
Developers often try to import `dnspython` using `import dnspython`, but the primary module to import from the `dnspython` package is `dns` (e.g., `import dns.resolver`).
fix
Change your import statement from `import dnspython` to `import dns` (or more specifically, `import dns.resolver`, `import dns.message`, etc., depending on what you need).
dns.resolver.NXDOMAIN: None of DNS query names exist
This error occurs when the queried domain name does not exist according to the configured DNS nameservers. This can be due to a typo in the domain, the domain truly not existing, or issues with the nameservers being used.
fix
Verify the domain name for typos. If the name is correct, try configuring the resolver to use different or public nameservers (e.g., Google's 8.8.8.8) using `resolver = dns.resolver.Resolver(); resolver.nameservers = ['8.8.8.8']` or explicitly checking different nameservers.
dns.resolver.NoAnswer
This exception is raised when the queried domain name exists, but there is no DNS record of the specific type requested (e.g., asking for an MX record where only A records exist).
fix
Catch the `dns.resolver.NoAnswer` exception in a `try-except` block to handle cases where no record of the specified type is found. Alternatively, when using `resolver.query()`, set `raise_on_no_answer=False` if you want to inspect the response even if no answer section is present.
dns.resolver.LifetimeTimeout: The resolution lifetime expired
The DNS query or the overall resolution process took longer than the specified `lifetime` or `timeout` setting, meaning no response was received from any nameserver within the allotted time. This often indicates network issues, slow DNS servers, or restrictive firewall rules.
fix
Increase the `lifetime` and/or `timeout` parameters for your resolver. For example: `resolver = dns.resolver.Resolver(); resolver.timeout = 5; resolver.lifetime = 10`. Also, ensure that your network configuration allows DNS queries to the target nameservers.
Upgrade
Version history
2.8.0latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
4
seranking-bot
4
ahrefsbot
2
Amazon
1
amazonbot
1
Resources