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\li b\encodings\utf _8.py", line 16, in decode
return codecs.utf_8_de code(input, errors, True)
UnicodeEncodeEr ror: '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 UnicodeDecodeEr ror:
try:
output = "Different: (%s) %s : %s # %s" %
(id[2],id[3],id[0],id[1])
print output.decode(' iso8859-15')
except UnicodeDecodeEr ror:
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\li b\encodings\utf _8.py", line 16, in decode
return codecs.utf_8_de code(input, errors, True)
UnicodeEncodeEr ror: '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 UnicodeDecodeEr ror:
try:
output = "Different: (%s) %s : %s # %s" %
(id[2],id[3],id[0],id[1])
print output.decode(' iso8859-15')
except UnicodeDecodeEr ror:
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.
Comment