Reputation: 11
Code:
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')
Error:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9c in position 19: character maps to <undefined>
I tried searching for web with no luck.
Upvotes: 0
Views: 134
Reputation: 76
Since you're dealing with images, try to open their bytes, use "rb" instead of "r":
fs.put(open('C:\\Users\\Mihir\\Desktop\\Python with web interface\\crap\\Capture.PNG', 'rb'), filename = 'images')
Python is trying to convert the image bytes into string
Upvotes: 1