This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: UnicodeEncodeError
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, mdtausifiqbal, steven.daprano
Priority: normal Keywords:

Created on 2020-11-23 08:36 by mdtausifiqbal, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg381650 - (view) Author: Md Tausif Iqbal (mdtausifiqbal) Date: 2020-11-23 08:36
my application crashes

 File "c:\users\tausif\appdata\local\programs\python\python38-32\lib\", line 154, in writerow
    return self.writer.writerow(self._dict_to_list(rowdict))
  File "c:\users\tausif\appdata\local\programs\python\python38-32\lib\encodings\", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 22-29: character maps to <undefined>

I know this error is occurring due to a Hindi Language character.
msg381655 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2020-11-23 09:07
The default encoding for files in Windows is the process active code page, which defaults to the system code page, e.g. code page 1252 if the system locale is "en-IN". You need to explicitly use a Unicode encoding such as UTF-8 when opening the file, e.g. open('some.csv', newline='', encoding='utf-8').
msg381656 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-11-23 09:11
You can learn more about unicode and encodings:

(For the last link, use the arrow keys to navigate.)
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86607
2020-11-23 09:11:51steven.dapranosetnosy: + steven.daprano
messages: + msg381656
2020-11-23 09:07:04eryksunsetstatus: open -> closed

type: crash -> behavior

nosy: + eryksun
messages: + msg381655
resolution: not a bug
stage: resolved
2020-11-23 08:36:35mdtausifiqbalcreate