2017-02-15 35 views
0

代碼:錯誤消息的MongoDB

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> 

我試圖尋找,沒有運氣網絡。

回答

1

既然你處理圖像,嘗試打開自己的字節,使用「RB」代替「R」

fs.put(open('C:\\Users\\Mihir\\Desktop\\Python with web interface\\crap\\Capture.PNG', 'rb'), filename = 'images') 

Python是試圖將圖像轉換成字節串