代码:
import pymongo, gridfs
client = MongoClient("localhost", 27017)
db = client.gridfs_example
fs = gridfs.GridFS(db)
fs.list()
fs.put(open('C:\\Users\\Mihir\\Desktop\\Python with web interface\\crap\\Capture.PNG', 'r'), filename = 'images')
错误:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9c in position 19: character maps to <undefined>
我试着没有运气搜索网页。
答案 0 :(得分:1)
由于您正在处理图片,请尝试打开他们的字节,使用“rb”而不是“r”:
fs.put(open('C:\\Users\\Mihir\\Desktop\\Python with web interface\\crap\\Capture.PNG', 'rb'), filename = 'images')
Python正在尝试将图像字节转换为字符串