簡體   English   中英

python龍卷風中的“ TypeError”簡單get方法可訪問Mongodb中的記錄

[英]“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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM