UnicodeEncodeError:'charmap'编解码器无法编码位置124的字符'\ u263a':字符映射到<undefined>

时间:2018-02-27 14:27:16

标签: python encoding

我理解错误与charector编码有关,但不确定如何修复它。

错误详情:

UnicodeEncodeError: 'charmap' codec can't encode character '\u263a' in position 124: character maps to <undefined>

这是发生的错误:

csv_writer.writerow(data_tmp_dict)

1 个答案:

答案 0 :(得分:1)

尝试将其解码为UTF-8

# -*- coding: utf-8 -*-
data_tmp_dict = {'key': 'value'.encode("utf-8")}
# or
data_tmp_dict = {'key': 'value'.encode("ascii")}