prevent crashing when logging object unable to be converted to unicode
This commit is contained in:
parent
a69c50f470
commit
c574234927
1 changed files with 7 additions and 2 deletions
|
@ -47,6 +47,8 @@ if is_py2:
|
|||
def u(text):
|
||||
if text is None:
|
||||
return None
|
||||
if isinstance(text, unicode):
|
||||
return text
|
||||
try:
|
||||
return text.decode('utf-8')
|
||||
except:
|
||||
|
@ -58,8 +60,11 @@ if is_py2:
|
|||
except:
|
||||
try:
|
||||
return text.decode('utf-8', 'replace')
|
||||
except AttributeError:
|
||||
except:
|
||||
try:
|
||||
return unicode(str(text))
|
||||
except:
|
||||
return unicode('')
|
||||
|
||||
elif is_py3:
|
||||
def u(text):
|
||||
|
|
Loading…
Reference in a new issue