When you get an error, you call whois_loop()
again from inside do_whois
, which means you can end up several recursive calls deep, hence the multiple "Ending loop here..."
. This is unnecessary. The loop will continue once do_whois
returns, whether or not you have handled an error inside it (indeed, the point of handling the error "quietly" inside the function is that the calling function doesn't have to know about it).
Instead, try:
def do_whois(domain):
try:
w = whois.get_whois(domain)
except:
print 'Some error...'
else:
print 'Everything OK'
return w
(Note that it is good practice to have as little as possible in try
; the else
part runs if no error is raised, so you can continue there.)