From 9ca58f5a00129d85de8712c625db68c96b2accee Mon Sep 17 00:00:00 2001 From: Frederik Kriewitz Date: Wed, 4 Jun 2014 14:00:53 +0000 Subject: [PATCH 2/3] gracefully handle non UTF-8 output of whois Fixes exeptions like this (in case whois returns non utf-8 output): ERROR in CGI: Traceback (most recent call last): File "/var/www/html/ulg.py", line 775, in handler.whois(**params) File "/var/www/html/ulg.py", line 738, in whois print self.runULGWhois(key,objtype) File "/var/www/html/ulg.py", line 710, in runULGWhois res = whois.lookup(key) File "/var/www/html/whois.py", line 43, in lookup res=res+l.decode('utf-8') File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) UnicodeDecodeError: 'utf8' codec can't decode byte 0xf3 in position 24: invalid continuation byte --- whois.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/whois.py b/whois.py index a232c10..f134973 100644 --- a/whois.py +++ b/whois.py @@ -40,7 +40,7 @@ def lookup(key): if(re.match('^\s*$',l) and not begin): continue if(l[0] != '%'): - res=res+l.decode('utf-8') + res=res+l.decode('utf-8', errors='replace') begin = True return res @@ -57,6 +57,6 @@ def lookup_as_name(asn): m = asname_regex.match(l) if(m): asname_cache[asn] = m.group(2) - return m.group(2).decode('utf-8') + return m.group(2).decode('utf-8', errors='replace') return defaults.STRING_UNKNOWN -- 1.9.1