to_unicode: handle new common errors
This commit is contained in:
parent
cb152b0146
commit
c2e008bda1
1 changed files with 6 additions and 3 deletions
|
|
@ -104,14 +104,17 @@ def to_unicode(text):
|
||||||
if isinstance(text, unicode):
|
if isinstance(text, unicode):
|
||||||
return text
|
return text
|
||||||
if not isinstance(text, str):
|
if not isinstance(text, str):
|
||||||
text = str(text)
|
try:
|
||||||
|
text = str(text)
|
||||||
|
except UnicodeError:
|
||||||
|
return unicode(text)
|
||||||
try:
|
try:
|
||||||
return unicode(text, 'utf-8')
|
return unicode(text, 'utf-8')
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
try:
|
try:
|
||||||
return unicode(text, 'iso-8859-1')
|
return unicode(text, 'iso-8859-15')
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
return unicode(text, 'windows-1252')
|
return unicode(text, 'windows-1252', 'replace')
|
||||||
|
|
||||||
|
|
||||||
def utc2local(date):
|
def utc2local(date):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue