# HG changeset patch # User Richard Penman # Date 1484897618 -28800 # Node ID 95feee1af1da5574a3f92acc99a2356e1fa82142 # Parent ccd653a5426394da1f0e07d6739fbea341178145 encode domain at start issue #107 diff -r ccd653a54263 -r 95feee1af1da whois/__init__.py --- a/whois/__init__.py Fri Jan 20 15:25:04 2017 +0800 +++ b/whois/__init__.py Fri Jan 20 15:33:38 2017 +0800 @@ -14,6 +14,7 @@ from .whois import NICClient + def whois(url, command=False): # clean domain to expose netloc ip_match = re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", url) @@ -34,7 +35,7 @@ else: # try builtin client nic_client = NICClient() - text = nic_client.whois_lookup(None, domain, 0) + text = nic_client.whois_lookup(None, domain.encode('idna'), 0) return WhoisEntry.load(domain, text) diff -r ccd653a54263 -r 95feee1af1da whois/whois.py --- a/whois/whois.py Fri Jan 20 15:25:04 2017 +0800 +++ b/whois/whois.py Fri Jan 20 15:33:38 2017 +0800 @@ -86,6 +86,7 @@ break return nhost + def whois(self, query, hostname, flags, many_results=False): """Perform initial lookup with TLD whois server then, if the quick flag is false, search that result @@ -108,10 +109,10 @@ if hostname == NICClient.DENICHOST: query_bytes = "-T dn,ace -C UTF-8 " + query elif hostname.endswith(NICClient.QNICHOST_TAIL) and many_results: - query_bytes = '=' + query + query_bytes = '=' else: query_bytes = query - s.send((query_bytes).encode('idna') + b"\r\n") + s.send((query_bytes) + b"\r\n") # recv returns bytes while True: d = s.recv(4096)