Commit 2df681bf by Frederik Kriewitz Committed by Tomas Hlavacek

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 <module> 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 Signed-off-by: 's avatarTomas Hlavacek <tmshlvck@gmail.com>
parent 1a9d7416
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment