Pass all domains through encode('idna') in NICClient
authorEvgeni Kunev <evgeni.kunev@gmail.com>
Fri, 15 Aug 2014 13:31:24 +0300
changeset 34 f9da616f15cf
parent 33 8c4c05eb65f4
child 35 0de2468a27e8
Pass all domains through encode('idna') in NICClient This makes sure that non-ascii domains will be properly encoded in punnycode before sending the whois query to the server.
whois/whois.py
--- a/whois/whois.py	Fri Aug 15 11:59:58 2014 +0300
+++ b/whois/whois.py	Fri Aug 15 13:31:24 2014 +0300
@@ -127,12 +127,15 @@
         """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()
+            queryBytes = ("-T dn,ace -C UTF-8 " + query + "\r\n").encode('idna')
             # print 'queryBytes:', queryBytes
         else:
-            queryBytes = (query + "\r\n").encode()
+            queryBytes = (query + "\r\n").encode('idna')
         s.send(queryBytes)
         """recv returns bytes
         """