Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

django - error when using pywhois

I tryed to use pywhois to check domain availability:

import pywhois
try:
        w = pywhois.whois('domain_name')
        message='Domain is available' 
except:
        message='Domain is not available'

but I get this error:

'module' object has no attribute 'whois'

I installed pywhois with this command:

easy_install pywhois

It was installed successfully,what I missed?
Edit: the best and more stable way to check domain availability is this way:

try:
        import socket
    socket.gethostbyname_ex('domain_name') 
            message='Domain is not available'
except:
        message='Domain is available'
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
easy_install pywhois 

installs a different tool - it is a CLI tool - http://pypi.python.org/pypi/pywhois. To install the desired pywhois python lib, check it out from googlecode(hg clone https://code.google.com/p/pywhois/) or github (git clone https://github.com/unpluggd/pywhois.git)

and from the source dir run

python setup.py install

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...