# UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-14: character maps to \<undefined\>

**URL:** <https://discuss.python.org/t/unicodeencodeerror-charmap-codec-cant-encode-characters-in-position-0-14-character-maps-to-undefined/12814>\
**Category:** Python Help\
**Tags:** help\
**Created:** [December 31, 2021, 2:04pm UTC](https://discuss.python.org/t/unicodeencodeerror-charmap-codec-cant-encode-characters-in-position-0-14-character-maps-to-undefined/12814 "2021-12-31T14:04:14Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![eryksun](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/eryksun/32/697_2.png) [@eryksun](https://discuss.python.org/u/eryksun)\
**Post date:** [January 1, 2022, 7:20am UTC](https://discuss.python.org/t/unicodeencodeerror-charmap-codec-cant-encode-characters-in-position-0-14-character-maps-to-undefined/12814/4 "2022-01-01T07:20:03Z")

</div>

> [@morningsashimi](#):
>
> print(“\u672c\u63a5\u53e3\u5373\u5c06\u505c\u6b62\u66f4\u65b0\uff0c\u8bf7\u5c3d\u5feb\u4f7f\u7528Pro\u7248\u63a5\u53e3\uff1ahttps://waditu.com/document/2”)  
> File “D:\Python310\lib\encodings\cp1252.py”, line 19, in encode  
> return codecs.charmap\_encode(input,self.errors,encoding\_table)[0]  
> UnicodeEncodeError: ‘charmap’ codec can’t encode characters in position 0-14: character maps to

In Python 3.6+, output to a Windows console file uses Unicode. All other files, however, default to using the process ANSI code page, which is typically a legacy encoding. The latter includes the standard files (i.e. stdin, stdout, stderr) when they’re redirected to something other than a console, such as a disk file or pipe. In your case the encoding of `sys.stdout` is code page 1252, maybe because the output is piped to Eclipse. There are two environment variables that you can set to override the encoding of `sys.stdout`. To force just the standard files to use UTF-8 , set `PYTHONIOENCODING=utf-8`. To use UTF-8 as the default in all cases, enable UTF-8 mode via `PYTHONUTF8=1`. To configure the latter for a single running instance of Python, use the command-line option `-X utf8` instead of setting `PYTHONUTF8=1`.

---

_[View the full topic](https://discuss.python.org/t/unicodeencodeerror-charmap-codec-cant-encode-characters-in-position-0-14-character-maps-to-undefined/12814)._
