{"id":347,"library":"dnspython","title":"dnspython","description":"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.","status":"active","version":"2.8.0","language":"python","source_language":"en","source_url":"https://github.com/rthalley/dnspython","tags":["DNS","networking","Python"],"install":[{"cmd":"pip install dnspython","lang":"bash","label":"Install dnspython"}],"dependencies":[],"imports":[{"note":"Ensure 'dns' is not shadowed by a local module named 'dns'.","symbol":"dns.resolver","correct":"import dns.resolver"},{"note":"Ensure 'dns' is not shadowed by a local module named 'dns'.","symbol":"dns.query","correct":"import dns.query"}],"quickstart":{"code":"import dns.resolver\n\n# Query for A records of 'example.com'\nresult = dns.resolver.resolve('example.com', 'A')\nfor ipval in result:\n    print('IP', ipval.to_text())","lang":"python","description":"This script queries the A records for 'example.com' and prints each IP address."},"warnings":[{"fix":"Update your code to align with the new function signatures and behaviors as per the dnspython 2.0.0 release notes.","message":"In 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.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Rename your script to a different name to prevent import conflicts.","message":"Avoid naming your script 'dns.py' to prevent import conflicts with the dnspython library.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T13:12:34.762Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the `dnspython` package using pip: `pip install dnspython`","cause":"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.","error":"ModuleNotFoundError: No module named 'dns'"},{"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).","cause":"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`).","error":"ModuleNotFoundError: No module named 'dnspython'"},{"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.","cause":"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.","error":"dns.resolver.NXDOMAIN: None of DNS query names 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.","cause":"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).","error":"dns.resolver.NoAnswer"},{"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.","cause":"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.","error":"dns.resolver.LifetimeTimeout: The resolution lifetime expired"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.21,"mem_mb":7,"disk_size":"20.3M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.14,"mem_mb":7,"disk_size":"21M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.3,"mem_mb":7.9,"disk_size":"22.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.24,"mem_mb":7.9,"disk_size":"23M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.23,"mem_mb":7.6,"disk_size":"14.5M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.24,"mem_mb":7.6,"disk_size":"15M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.21,"mem_mb":7.4,"disk_size":"14.2M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.21,"mem_mb":7.4,"disk_size":"15M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.14,"mem_mb":5.8,"disk_size":"19.7M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.13,"mem_mb":5.8,"disk_size":"20M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}