3

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'
Asma Gheisari
  • 5,794
  • 9
  • 30
  • 51
  • `pip install python-whois` to install; `import whois` to import. – SparkAndShine Jul 23 '15 at 19:54
  • The edit is incorrect. It's quite possible for a domain to be registered and thus not available for registration, yet to not have an IP address assigned to the domain name. Parked domains might not have IP addresses at all; many sites register an IP address for e.g. www.domainname but do not assign an IP address to just the domain name. – tripleee Apr 04 '17 at 06:08

2 Answers2

2
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
Tisho
  • 8,320
  • 6
  • 44
  • 52
2

The project pywhois is moved to Bitbucket, here.

To install pywhois,

pip install python-whois

To use pywhois (import whois), here is an example.

import whois            
#check if a domain name is registered or not
try :
    w = whois.whois(url)
except (whois.parser.PywhoisError):  #NOT FOUND
    print(url)   #unregistered domain names, it is not very accurate.

A kind reminder that using pywhois is not very accurate. For more info, you can refer this question.

Community
  • 1
  • 1
SparkAndShine
  • 17,001
  • 22
  • 90
  • 134