json - "TypeError" simple get method in python tornado to access record from Mongodb -


hi have started programming in python (i newbie python programming). have small collection of data in mongodb.i have written simple method find data collection. have error returning fetched value.

here code:

import bson bson import json_util bson.json_util import dumps  class typelist(apihandler):     @gen.coroutine     def get(self):         doc = yield db.vtype.find_one()         print(doc)         = self.write(json_util.dumps(doc))         return      def options(self):         pass 

it gives me fetched data.

but when replace these lines

a = self.write.... return a

with return bson.json_util.dumps({ 'success': true, 'mycollectionkey': doc })

it gives me type error.

typeerror: expected none, got {'success': true, 'mycollectionkey': {'type': 1, 'item': 'cookie'}}

can explain me why error , there anyway solve problem.

thanks in advance.

requesthandler.get() not supposed return anything. error warning you returned value being ignored. tornado handlers produce output calling self.write(), not returning value.


Comments