This is my MongoDB Database :
And with my python code, i want to print all Documents of Collection name "accessLog" This is my Python Code (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
How i can fix this code Thanks very much !
Use unidecode
to convert unicode data to ASCII text and then print the record.
import unidecode
for record in collection.find({}):
print unidecode.unidecode_expect_nonascii(record)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.