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

Nobody nobody at nowhere.com
Fri Jul 17 03:20:15 EDT 2009


On Thu, 16 Jul 2009 20:26:39 -0700, akhil1988 wrote:

> Well, you were write: unintentionally I removed strip(). But the problem does
> not ends here:
> 
> I get this error now:
> 
>  File "./temp.py", line 488, in <module>
>     main()
>   File "./temp.py", line 475, in main
>     for line in sys.stdin:
>   File "/usr/local/lib/python3.1/codecs.py", line 300, in decode
>     (result, consumed) = self._buffer_decode(data, self.errors, final)
> UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-2: invalid
> data
> 
> for this line:
> â

Right. You're running in a locale whose encoding is UTF-8, but feeding
data which isn't valid UTF-8 to stdin. If you want to use data with a
different encoding, you need to replace sys.stdin, e.g.:

import sys
import io
sys.stdin = io.TextIOWrapper(sys.stdin.detach(), encoding = 'iso-8859-1')




More information about the Python-list mailing list