<br><br><div class="gmail_quote">On Thu, Jan 29, 2009 at 11:24 AM, Anjanesh Lekshminarayanan <span dir="ltr"><<a href="mailto:mail@anjanesh.net">mail@anjanesh.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Im reading a file. But there seems to be some encoding error.<br>
<br>
>>> f = open(filename)<br>
>>> data = f.read()<br>
Traceback (most recent call last):<br>
  File "<pyshell#2>", line 1, in <module><br>
    data = f.read()<br>
  File "C:\Python30\lib\io.py", line 1724, in read<br>
    decoder.decode(self.buffer.read(), final=True))<br>
  File "C:\Python30\lib\io.py", line 1295, in decode<br>
    output = self.decoder.decode(input, final=final)<br>
  File "C:\Python30\lib\encodings\cp1252.py", line 23, in decode<br>
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]<br>
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position<br>
10442: character maps to <undefined><br>
<br>
The string at position 10442 is something like this :<br>
"query":"0 1ยปร  \u2021 0\u201a0 \u2021ยปร ","<br>
<br>
So what encoding value am I supposed to give ? I tried f =<br>
open(filename, encoding="cp1252") but still same error. I guess<br>
Python3 auto-detects it as cp1252</blockquote><div><br>It does auto-detect it as cp1252- look at the files in the traceback and you'll see lib\encodings\cp1252.py. Since cp1252 seems to be the wrong encoding, try opening it as utf-8 or latin1 and see if that fixes it.<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
--<br>
Anjanesh Lekshmnarayanan<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>