a stable way to check domain availability with pywhois

点点圈 提交于 2019-12-11 17:39:58

问题


I use this code to check domain availability:

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

It returns this result:

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']

When internet speed is low it doesn't work stable and return wrong result. What is an accurate way to check the result to get a stable response?


回答1:


"internet speed is low" certainly means your request times out. You can catch that by specifying an exception on your except line:

except socket.timeout:

If you catch such an exception, you'll have to retry your request again later.



来源:https://stackoverflow.com/questions/11584942/a-stable-way-to-check-domain-availability-with-pywhois

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!