Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 248193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:19:21+00:00 2026-05-11T21:19:21+00:00

I’m trying to use the dnspython library, and am a little confused by their

  • 0

I’m trying to use the dnspython library, and am a little confused by their example for querying MX records on this page: http://www.dnspython.org/examples.html:

import dns.resolver

answers = dns.resolver.query('dnspython.org', 'MX')
for rdata in answers:
    print 'Host', rdata.exchange, 'has preference', rdata.preference

In the python CLI, a dir(answers) gives me:

['__class__', '__delattr__', '__delitem__', '__delslice__', '__dict__', '__doc__', '__getattr__', '__getattribute__', '__getitem__', '__getslice__', '__hash__', '__init__', '__iter__', '__len__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 'expiration', 'qname', 'rdclass', 'rdtype', 'response', 'rrset']

Two things are confusing to me (which are related):

  • Iteration over the answers object. What is rdata in the example?
  • None of the attributes or methods of answers matches exchange or preference. Clearly rdata is not just a simple alias of answers, but I don’t understand where those attributes are coming from.
    • 1 1 Answer
    • 0 Views
    • 0 Followers
    • 0
    Share
    • Facebook
    • Report

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    1 Answer

    • Voted
    • Oldest
    • Recent
    • Random
    1. Editorial Team
      Editorial Team
      2026-05-11T21:19:21+00:00Added an answer on May 11, 2026 at 9:19 pm

      I haven’t looked at dns.resolver as of yet – I just added it to the ever-growing list of things to check out. I would guess that rdata refers to the resource record type specific data as described in Section 4.1.3 of RFC1035. The response of a DNS request contains three data sections in addition to the query and headers:

      1. Answers
      2. Authoritative Name Server records
      3. Additional Resource records

      From the looks of it dns.resolver.query() is returning the first section. In this case, each resource record in the answer section is going to have different attributes based on the record type. In this case, you asked for MX records so the records should have exactly the attributes that you have – exchange and preference. These are described in Section 3.3.9 of RFC1035.

      I suspect that dns.resolver is overriding __getattr__ or something similar to perform the magic that you are seeing so you won’t see the fields directly in a dir(). Chances are that you are safe using the attributes as defined in RFC1035. I will definitely have to check this out tomorrow since I have need of a decent DNS subsystem for Python.

      Thanks for mentioning this module and have fun with DNS. It is really pretty interesting stuff if you really dig into how it works. I still think that it is one of the earlier expressions of that ReSTful thing that is all the rage these days 😉

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Related Questions

    Basically, what I'm trying to create is a page of div tags, each has
    I am trying to understand how to use SyndicationItem to display feed which is
    I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
    I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
    I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
    link Im having trouble converting the html entites into html characters, (&# 8217;) i
    That's pretty much it. I'm using Nokogiri to scrape a web page what has
    For some reason, after submitting a string like this Jack’s Spindle from a text
    this is what i have right now Drawing an RSS feed into the php,
    I am trying to render a haml file in a javascript response like so:

    Explore

    • Home
    • Add group
    • Groups page
    • Communities
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Polls
    • Tags
    • Badges
    • Users
    • Help
    • SEARCH

    Footer

    © 2021 The Archive Base. All Rights Reserved
    With Love by The Archive Base

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.