UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in

Discussion in 'Python' started by Anjanesh Lekshminarayanan, Jan 29, 2009.

  1. Im reading a file. But there seems to be some encoding error.

    >>> f = open(filename)
    >>> data = f.read()

    Traceback (most recent call last):
    File "<pyshell#2>", line 1, in <module>
    data = f.read()
    File "C:\Python30\lib\io.py", line 1724, in read
    decoder.decode(self.buffer.read(), final=True))
    File "C:\Python30\lib\io.py", line 1295, in decode
    output = self.decoder.decode(input, final=final)
    File "C:\Python30\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position
    10442: character maps to <undefined>

    The string at position 10442 is something like this :
    "query":"0 1Ȉ \u2021 0\u201a0 \u2021»Ã","

    So what encoding value am I supposed to give ? I tried f =
    open(filename, encoding="cp1252") but still same error. I guess
    Python3 auto-detects it as cp1252
    --
    Anjanesh Lekshmnarayanan
     
    Anjanesh Lekshminarayanan, Jan 29, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robin Siebler
    Replies:
    4
    Views:
    27,418
    Tim Peters
    Oct 8, 2004
  2. Benjamin Peterson
    Replies:
    0
    Views:
    474
    Benjamin Peterson
    Jan 29, 2009
  3. John Machin
    Replies:
    0
    Views:
    1,020
    John Machin
    Jan 29, 2009
  4. John Machin
    Replies:
    0
    Views:
    528
    John Machin
    Jan 30, 2009
  5. Anjanesh Lekshminarayanan
    Replies:
    0
    Views:
    1,327
    Anjanesh Lekshminarayanan
    Feb 27, 2009
Loading...

Share This Page