def on_get(self, req, resp, database, collection, doc_str):
try:
doc = urllib.unquote(doc).decode("utf8")
doc = ast.literal_eval(doc)
ret = self.client[database][collection].insert_one(doc)
ret = str(ret.inserted_id)
except:
ret = "Error inserting document into database."
After Change
def on_get(self, req, resp, database, collection, doc_str):
try:
if not bson.is_valid(doc_str):
doc_str = bson.BSON.encode(doc_str)
ret = self.client[database][collection].insert_one(doc_str)
ret = str(ret.inserted_id)
except:
ret = "Error inserting document into database."