用pywhois检查域可用性的稳定方法

时间:2012-07-20 18:25:15

标签: python pywhois

我使用此代码检查域可用性:

try:
    w = pywhois.whois('honarasai.com')
    if not w:
        message='Domain is available'
except:
    message='Domain is taken'

返回此结果:

creation_date: ['11-jun-2012'] domain_name: ['HONARASAI.COM', 'honarasai.com'] emails: ['domain@netafraz.com', 'domain@netafraz.com', 'domain@netafraz.com', 'domain@netafraz.com'] expiration_date: ['11-jun-2013'] name_servers: ['NS.HONARASAI.COM', 'NS2.HONARASAI.COM'] referral_url: ['http://www.OnlineNIC.com'] registrar: ['ONLINENIC, INC.'] status: ['clientTransferProhibited'] updated_date: ['11-jun-2012'] whois_server: ['whois.onlinenic.com']

当互联网速度较低时,它无法正常工作并返回错误的结果。检查结果以获得稳定响应的准确方法是什么?

1 个答案:

答案 0 :(得分:2)

“互联网速度低”肯定意味着您的请求超时。您可以通过在except行指定例外来捕捉到这一点:

except socket.timeout:

如果你遇到这样的例外,你将不得不在以后再次重试你的请求。

相关问题