# HG changeset patch # User Richard Penman # Date 1439360041 -28800 # Node ID 7636ed3adf862e319ee59d91447831757075093c # Parent e2eaf1755fcea6ecfe59092dde02290cfc29f371# Parent 1f80f6dec7ac1a7676a5fec1f0845f1b0ea49e85 merged diff -r e2eaf1755fce -r 7636ed3adf86 whois/whois.py --- a/whois/whois.py Wed Aug 12 11:41:38 2015 +0600 +++ b/whois/whois.py Wed Aug 12 14:14:01 2015 +0800 @@ -122,31 +122,35 @@ # print 'Performing the whois' # print 'parameters given:', query, hostname, flags # pdb.set_trace() - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect((hostname, 43)) - """send takes bytes as an input - """ - queryBytes = None - if type(query) is not unicode: - query = query.decode('utf-8') + try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(2) + s.connect((hostname, 43)) + """send takes bytes as an input + """ + queryBytes = None + if type(query) is not unicode: + query = query.decode('utf-8') - if (hostname == NICClient.DENICHOST): - # print 'the domain is in NIC DENIC' - queryBytes = ("-T dn,ace -C UTF-8 " + query + "\r\n").encode('idna') - # print 'queryBytes:', queryBytes - else: - queryBytes = (query + "\r\n").encode('idna') - s.send(queryBytes) - """recv returns bytes - """ - # print s - response = b'' - while True: - d = s.recv(4096) - response += d - if not d: - break - s.close() + if (hostname == NICClient.DENICHOST): + # print 'the domain is in NIC DENIC' + queryBytes = ("-T dn,ace -C UTF-8 " + query + "\r\n").encode('idna') + # print 'queryBytes:', queryBytes + else: + queryBytes = (query + "\r\n").encode('idna') + s.send(queryBytes) + """recv returns bytes + """ + # print s + response = b'' + while True: + d = s.recv(4096) + response += d + if not d: + break + s.close() + except socket.error as socketerror: + print("Error: ", socketerror) # pdb.set_trace() nhost = None # print 'response', response