使用pywhois时出错

时间:2012-07-20 12:00:13

标签: django pywhois

我尝试使用pywhois来检查域可用性:

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

但是我收到了这个错误:

'module' object has no attribute 'whois'

我使用以下命令安装了pywhois

easy_install pywhois

安装成功,我错过了什么?
修改 以这种方式检查域可用性的最佳和更稳定的方法是:

try:
        import socket
    socket.gethostbyname_ex('domain_name') 
            message='Domain is not available'
except:
        message='Domain is available'

2 个答案:

答案 0 :(得分:2)

easy_install pywhois 

安装另一个工具 - 它是一个CLI工具 - http://pypi.python.org/pypi/pywhois。 要安装所需的pywhois python lib,请从googlecode(hg clone https://code.google.com/p/pywhois/)或github(git clone https://github.com/unpluggd/pywhois.git)中查看

并从源目录运行

python setup.py install

答案 1 :(得分:1)

项目IBActions已移至Bitbucket,here

安装pywhois

pywhois

要使用pip install python-whois pywhois),这是一个示例。

import whois

提醒您使用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. 不是很准确。有关详细信息,请参阅this question