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

Dan Stromberg drsalists at gmail.com
Wed May 23 16:48:16 EDT 2018


On Sat, May 19, 2018 at 3:58 PM,  <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

As suggested by others, if this is a text file, request the encoding
from the person who created it.  chardet can't really autodetect all
encodings, and neither can guessing encodings in a more manual way -
though if there's no one to ask, sometimes chardet is better than not
reading the file :)

Or, if the file is not text, if you want to treat it as a binary blob:

$ pythons --command 'file_ = open("/usr/local/pypy3-6.0.0/bin/pypy3",
"rb"); data = file_.read(); print(type(data)); file_.close()'
below cmd output started 2018 Wed May 23 01:43:35 PM PDT
/usr/local/cpython-1.0/bin/python (1.0.1) good <type 'string'>
/usr/local/cpython-1.1/bin/python (1.1) good <type 'string'>
/usr/local/cpython-1.2/bin/python (1.2) good <type 'string'>
/usr/local/cpython-1.3/bin/python (1.3) good <type 'string'>
/usr/local/cpython-1.4/bin/python (1.4) good <type 'string'>
/usr/local/cpython-1.5/bin/python (1.5.2) good <type 'string'>
/usr/local/cpython-1.6/bin/python (1.6.1) good <type 'string'>
/usr/local/cpython-2.0/bin/python (2.0.1) good <type 'string'>
/usr/local/cpython-2.1/bin/python (2.1.0) good <type 'string'>
/usr/local/cpython-2.2/bin/python (2.2.0) good <type 'str'>
/usr/local/cpython-2.3/bin/python (2.3.0) good <type 'str'>
/usr/local/cpython-2.4/bin/python (2.4.0) good <type 'str'>
/usr/local/cpython-2.5/bin/python (2.5.6) good <type 'str'>
/usr/local/cpython-2.6/bin/python (2.6.9) good <type 'str'>
/usr/local/cpython-2.7/bin/python (2.7.13) good <type 'str'>
/usr/local/cpython-3.0/bin/python (3.0.1) good <class 'bytes'>
/usr/local/cpython-3.1/bin/python (3.1.5) good <class 'bytes'>
/usr/local/cpython-3.2/bin/python (3.2.5) good <class 'bytes'>
/usr/local/cpython-3.3/bin/python (3.3.3) good <class 'bytes'>
/usr/local/cpython-3.4/bin/python (3.4.2) good <class 'bytes'>
/usr/local/cpython-3.5/bin/python (3.5.0) good <class 'bytes'>
/usr/local/cpython-3.6/bin/python (3.6.0) good <class 'bytes'>
/usr/local/cpython-3.7/bin/python (3.7.0b3) good <class 'bytes'>
/usr/local/jython-2.7/bin/jython (2.7.0) good <type 'str'>
/usr/local/pypy-5.10.0/bin/pypy (2.7.13) good <type 'str'>
/usr/local/pypy-5.3.1/bin/pypy (2.7.10) good <type 'str'>
/usr/local/pypy-5.9.0/bin/pypy (2.7.13) good <type 'str'>
/usr/local/pypy-6.0.0/bin/pypy (2.7.13) good <type 'str'>
/usr/local/pypy3-5.10.0/bin/pypy3 (3.5.3) good <class 'bytes'>
/usr/local/pypy3-5.5.0/bin/pypy3 (3.3.5) good <class 'bytes'>
/usr/local/pypy3-5.8.0-with-lzma-fixes/bin/pypy3 (3.5.3) good <class 'bytes'>
/usr/local/pypy3-5.8.0/bin/pypy3 (3.5.3) good <class 'bytes'>
/usr/local/pypy3-5.9.0/bin/pypy3 (3.5.3) good <class 'bytes'>
/usr/local/pypy3-6.0.0/bin/pypy3 (3.5.3) good <class 'bytes'>
/usr/local/micropython-git-2017-06-16/bin/micropython (3.4.0) good
<class 'bytes'>

HTH



More information about the Python-list mailing list