G
Gilles Ganault
Hello
Data that I download from the web seems to be using different code
pages at times, and Python doesn't like this.
Google returned a way to handle this, but I'm still getting an error:
========
print output.decode('utf-8')
File "C:\Python25\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe2' in
position 47:
ordinal not in range(128)
========
Here's the code:
========
try:
output = "Different: (%s) %s : %s # %s" %
(id[2],id[3],id[0],id[1])
print output.decode('utf-8')
except UnicodeDecodeError:
try:
output = "Different: (%s) %s : %s # %s" %
(id[2],id[3],id[0],id[1])
print output.decode('iso8859-15')
except UnicodeDecodeError:
output = "Different: (%s) %s : %s # %s" %
(id[2],id[3],id[0],id[1])
print output.decode('cp1252')
========
Am I doing it wrong? Is there something else I should try?
Thank you.
Data that I download from the web seems to be using different code
pages at times, and Python doesn't like this.
Google returned a way to handle this, but I'm still getting an error:
========
print output.decode('utf-8')
File "C:\Python25\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe2' in
position 47:
ordinal not in range(128)
========
Here's the code:
========
try:
output = "Different: (%s) %s : %s # %s" %
(id[2],id[3],id[0],id[1])
print output.decode('utf-8')
except UnicodeDecodeError:
try:
output = "Different: (%s) %s : %s # %s" %
(id[2],id[3],id[0],id[1])
print output.decode('iso8859-15')
except UnicodeDecodeError:
output = "Different: (%s) %s : %s # %s" %
(id[2],id[3],id[0],id[1])
print output.decode('cp1252')
========
Am I doing it wrong? Is there something else I should try?
Thank you.