Python – string encoding and decoding

pythonpython-2.7

Here are my attempts with error messages. What am I doing wrong?

string.decode("ascii", "ignore")

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in
position 37: ordinal not in range(128)

string.encode('utf-8', "ignore")

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position
37: ordinal not in range(128)

Best Answer

You can't decode a unicode, and you can't encode a str. Try doing it the other way around.