简体   繁体   English

MongoDB中的Python错误“ UnicodeEncodeError:'charmap'编解码器无法编码字符”

[英]Python error “UnicodeEncodeError: 'charmap' codec can't encode character” in MongoDB

This is my MongoDB Database : 这是我的MongoDB数据库:

And with my python code, i want to print all Documents of Collection name "accessLog" This is my Python Code (python 3.4) 使用我的python代码,我要打印所有集合名称为“ accessLog”的文档。这是我的Python代码(python 3.4)

import pymongo 
from pymongo import *
import datetime
import sys

client = MongoClient('MyDatabase')

print('-----Access to Database cdt_log------')
db = client['cdt_log']
print(db)

collection = db['accessLog']

for record in collection.find({}):
    print(record)

But I had error : UnicodeEncodeError: 'charmap' codec can't encode character '\̣' in position 369: character maps to undefined 但是我遇到了错误:UnicodeEncodeError:'charmap'编解码器无法在位置369处编码字符'\\ u0323':字符映射为未定义

How i can fix this code Thanks very much ! 我该如何解决此代码,非常感谢!

Use unidecode to convert unicode data to ASCII text and then print the record. 使用unidecode将unicode数据转换为ASCII文本,然后打印记录。

import unidecode
for record in collection.find({}):
     print unidecode.unidecode_expect_nonascii(record)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UnicodeEncodeError:&#39;charmap&#39;编解码器无法编码字符 - UnicodeEncodeError: 'charmap' codec can't encode character UnicodeEncodeError: &#39;charmap&#39; 编解码器无法编码字符:字符映射到<undefined> - UnicodeEncodeError: 'charmap' codec can't encode character : character maps to <undefined> UnicodeEncodeError:&#39;charmap&#39;编解码器无法对字符字符映射进行编码<undefined> - UnicodeEncodeError: 'charmap' codec can't encode character character maps to <undefined> 字符编码错误:UnicodeEncodeError:&#39;charmap&#39;编解码器无法对位置Y中的字符X进行编码:字符映射到<undefined> - Character encoding error: UnicodeEncodeError: 'charmap' codec can't encode character X in position Y: character maps to <undefined> Pandas UnicodeEncodeError: &#39;charmap&#39; 编解码器无法编码字符 - Pandas UnicodeEncodeError: 'charmap' codec can't encode character Python 3-UnicodeEncodeError:“ charmap”编解码器无法编码字符(编码后在文件中) - python 3 - UnicodeEncodeError: 'charmap' codec can't encode character (Encode so it's in a file) UnicodeEncodeError:&#39;charmap&#39;编解码器无法编码字符...问题 - UnicodeEncodeError: 'charmap' codec can't encode character… problems UnicodeEncodeError:&#39;charmap&#39;编解码器无法编码字符&#39;\\ u2264&#39; - UnicodeEncodeError: 'charmap' codec can't encode character '\u2264' Python UnicodeEncodeError:使用 GEOPY 时无法编码“charmap”编解码器 - Python UnicodeEncodeError: 'charmap' codec can't encode when using GEOPY Python,UnicodeEncodeError:“ charmap”编解码器无法在位置编码字符 - Python, UnicodeEncodeError: 'charmap' codec can't encode characters in position
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM