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

Peter Otten __peter__ at web.de
Sun May 20 03:55:11 EDT 2018


bellcanadardp at gmail.com wrote:

> On Thursday, 29 January 2009 12:09:29 UTC-5, Anjanesh Lekshminarayanan 
> wrote:
>> > 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.
>> 
>> Thanks a lot ! utf-8 and latin1 were accepted !
> 
> hello i am having same issue..i believe the code is written in python 2
> and i am running python 3.6..i tried at the interpreter..f =
> open(filename, encoding="utf-8" and also latin-1..but then when i run my
> file i still get the error...also my line is at 7414..how do you find this
> line??...is it better to try to run the file .py in python 2??..thnxz

open(filename, encoding="latin-1") will succeed with *every* file -- the 
characters may be nonsensical, but you will *not* get a UnicodeDecodeError.

> ...is it better to try to run the file .py in python 2?

Not "better", but perhaps easier. If the code works with Python 2 then I 
recommend that you use that.

If you want help to debug it you need to provide some of the relevant source 
code and -- first and foremost -- the traceback.

> my line is at 7414..how do you find this line?

Read the traceback carefully. It should contain both filename and line.




More information about the Python-list mailing list