close

[Solved] UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x9d in position X: character maps to

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x9d in position X: character maps to <undefined> in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x9d in position X: character maps to <undefined> Error Occurs?

Today I get the following error UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x9d in position X: character maps to <undefined> in python.

How To Solve UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x9d in position X: character maps to <undefined> Error ?

  1. How To Solve UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position X: character maps to Error ?

    To Solve UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position X: character maps to <undefined> Error The problem is caused during the setup process when reading README.txt. In Windows, the default encoding is cp1252, but that readme file is most likely encoded in UTF8.

  2. UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position X: character maps to

    To Solve UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position X: character maps to <undefined> Error The problem is caused during the setup process when reading README.txt. In Windows, the default encoding is cp1252, but that readme file is most likely encoded in UTF8.

Solution 1

The problem is caused during the setup process when reading README.txt. In Windows, the default encoding is cp1252, but that readme file is most likely encoded in UTF8.

The error message tells you that cp1252 codec is unable to decode the character with the byte 0x9D. When I browsed through the readme file, I found this character:  (also known as: “RIGHT DOUBLE QUOTATION MARK”), which has the bytes 0xE2 0x80 0x9D, which includes the problematic byte.

What you can do is:

  1. Download the package here
  2. Decompress the package
  3. Open setup.py
  4. Change the following:

From:

with open('README.txt') as file:
    long_description = file.read()

Change into:

with open('README.txt', encoding="utf8") as file:
    long_description = file.read()

This will open the file with the proper encoding.

Or you can remove these two line altogether and also remove long_description=long_description, at line 18 inside setup().

  1. In console, run python setup.py install
  2. And you’re done!

Since there’s no actual setup in the setup.py script, you can just directly clone the source folder from GitHub, the package should still work properly.

Solution 2

Simply add encoding="utf8" inside “open(‘path’, here)”.

with open('path to csv file',  encoding="utf8") as csv_file:

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read