[英]“TypeError” simple get method in python tornado to access record from Mongodb
嗨,我最近开始用Python编程(我是python编程的新手)。 我的MongoDB中只有一小部分数据,我编写了一个简单的get方法来查找我的数据集中的所有数据。 但返回获取的值时出错。
这是我的代码:
import bson
from bson import json_util
from bson.json_util import dumps
class TypeList(APIHandler):
@gen.coroutine
def get(self):
doc = yield db.vtype.find_one()
print(doc)
a = self.write(json_util.dumps(doc))
return a
def options(self):
pass
它给了我获取的数据。
但是当我替换这些行时
a = self.write.... return a
return bson.json_util.dumps({ 'success': True, 'mycollectionKey': doc })
它给我一个类型错误。
TypeError: Expected None, got {'success': True, 'mycollectionKey': {'type': 1, 'item': 'cookie'}}
谁能解释我为什么会收到此错误,并且仍然可以解决该问题。
提前致谢。
RequestHandler.get()
不应该返回任何内容。 此错误只是警告您返回了被忽略的值。 龙卷风处理程序通过调用self.write()而不是返回值来产生输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.