我有一个字典data_dump列表,其中包含像这样的字典:
d = {"ids": s_id, "subject": subject}
我正在按照本教程尝试进行批量插入:
connection = Connection(host,port)
db = connection['clusters']
posts = db.posts
posts.insert(data_dump)
失败并显示以下错误:
File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 312, in insert
continue_on_error, self.__uuid_subtype), safe)
bson.errors.InvalidStringData: strings in documents must be valid UTF-8
请指教.
谢谢
解决方法:
解决了:
好吧..强制编码
1)去除符号串等
接着
2)通过raw.decode(‘ascii’)将ascii转换为utf-8,然后再解码_string.encode(‘utf8’)
多谢你们.. :)