1

I am trying to use the dnspython in my code but when it gets to the import statement, I get the following error:

>>> import DNS.resolver
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\python27\lib\site-packages\DNS\resolver.py", line 31, in <module>
    import dns.exception
ImportError: No module named dns.exception

I have tried installing with pip, easy_install and manually from the git repo but nothing seems to do the trick. Any ideas??

Code:

import DNS.resolver

if __name__ == "__main__":

    domain = 'hotmail.com'
    for x in dns.resolver.query(domain, 'MX'):
        print x.to_text()
TomSelleck
  • 6,706
  • 22
  • 82
  • 151

3 Answers3

3

Another thing you can do to fix problems with this package is to install python-dnspython again using Synaptic. (Whether no having previous problems about duplicity)

Sometimes if you try to install this package using pip could appear some problems like that:

Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/dnspython Storing debug log for failure in /root/.pip/pip.log

Using Synaptic cleans the old files and install the new ones, from that package. I know this issue is solved but I wanted to add more information about this :)

Joanmacat
  • 1,442
  • 1
  • 10
  • 13
2

That's because package and module names are lowercase (see PEP 8). This works just fine :

import dns.resolver
import dns.exception

You should also be careful that none of your own *.py filename conflicts with the dns package. Your *.py file should not be named dns.py. Pay also attention to the *.pyc files.

2

First, your code should be : import dns.resolver.

There seems to be an issue installing dnspython using pip, you should clone the dnspython repository using git and run the file setup.py as follows:

git clone https://github.com/rthalley/dnspython
cd dnspython\
python setup.py install

If you don't have git installed on your machine, you can just download the repository manually .

SEDaradji
  • 1,348
  • 15
  • 18