[英]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.