UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to <undefined>

pjmclenon at gmail.com pjmclenon at gmail.com
Sun Oct 21 07:33:24 EDT 2018


On Thursday, January 29, 2009 at 11:24:46 AM UTC-5, Anjanesh Lekshminarayanan wrote:
> 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

hello peter, mrab and terry

thank you all for answering
i decided to use the last option by terry....latin -1....cuz it seemed the easiest to try 

it does work but i read somewhere if im not wrong ..that this is not really the advised thing to do ....but also my file was just simple text....i did see some weird caracters...and maybe that caused the utf-8 error..but i dont know how to post a pic here to show the caracters in my text file...but anyway for now i guess i will keep this setting..but not sure why this seems to be not the ideal thing to do with encoding at latin -1 , which is extened ascii right?/..and thats 256 options?/..and even with the unknown caraters i found in the file..isnt utf-8 like over 1 million options?

thzx alot  forum
Jessica



More information about the Python-list mailing list