第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Python Swagger 響應(yīng)變?yōu)榭眨‵lask、Flask_Restplus)

Python Swagger 響應(yīng)變?yōu)榭眨‵lask、Flask_Restplus)

狐的傳說 2022-01-18 16:15:36
我可以在終端中查看響應(yīng)內(nèi)容,但在招搖的 UI 中,它顯示為空。問題:為了調(diào)試,我嘗試從ret函數(shù)中的變量打印值json_response_from_dict(dict_),它向我顯示了我通過 swagger UI 輸入的值。但是在 Swagger UI 的響應(yīng)中,它是空的。但是在終端中的響應(yīng)中,它顯示<Response 141 bytes [200 OK]>并且終端中 ret 的值也顯示{"rec_id": 464, "frame_id_prob": [[1, 0.1], [2, 0.1], [3, 0.1], [4, 0.1], [5, 0.6]], "comment": "these frames suit everyone", "mine_id": NaN}我無法弄清楚該值在哪里丟失。MCVE:from flask import Flask, Blueprint, request, Responsefrom flask_restplus import Resource, Api, fieldsfrom flask.views import MethodViewimport jsonimport numpy as npdef json_response_from_dict(dict_):    """converts a python dictionary to a json string, and returns    a HHTP response for a JSON string    dict_ -- input python dictionary    """    ret = json.dumps(dict_)    print(ret)    resp = Response(response=ret,                    status=200,                    mimetype="application/json")    print(resp)    return respapp = Flask(__name__)api_v1 = Blueprint('api', __name__, url_prefix='/api/1')api = Api(api_v1, version='1.0', title='my API',    description='my API',)ns = api.namespace('my', description='my operations')myModel = api.model('my Model', {    'rec_id': fields.Integer(readOnly=True, description='Random Choice'),    'comment': fields.String(required=True, description='Comments'),    'mine_id' : fields.String(required=True, description='unique ECP ID')})# Register blueprint at URL# (URL must match the one given to factory function above)app.register_blueprint(api_v1)但同樣的問題仍然存在。
查看完整描述

1 回答

?
白衣染霜花

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超10個(gè)贊

@ns.route("/dev/get_rec_id", methods=["POST"])

@ns.param('mine_id', 'unique ECP ID')

class RecommendationService(Resource):

    @ns.doc('path to generate a unique recommendationid, and to determine which frames predictions can be made for. Expected/optional input :       JSON string as a https html data objects with keys: mine_id -- unique ECP ID. If this is not provided generic frames recommendations will be provided.')

    @ns.marshal_list_with(myModel)

    def post(self):

        mine_id = np.nan

        if request.is_json:

            mine_id = request.json.get('mine_id', np.nan)


        return {'rec_id': np.random.choice(1000),

            'fun_id_prob': [[1, 0.1], [2, 0.1], [3, 0.1], [4, 0.1], [5, 0.6]],

            'comment': 'these games suit everyone',

            'mine_id': mine_id

             }

在此簽名不匹配即fun_id_prob不在 API 簽名中,也由于某種原因在調(diào)用X-Fields時(shí),它需要保持為空。


只需使用


@ns.route("/dev/get_rec_id", methods=["POST"])

@ns.param('mine_id', 'unique ECP ID')

class RecommendationService(Resource):

    @ns.doc('path to generate a unique recommendationid, and to determine which frames predictions can be made for. Expected/optional input :       JSON string as a https html data objects with keys: mine_id -- unique ECP ID. If this is not provided generic frames recommendations will be provided.')

    @ns.marshal_list_with(myModel)

    def post(self):

        mine_id = np.nan

        if request.is_json:

            mine_id = request.json.get('mine_id', np.nan)


        return {'rec_id': np.random.choice(1000),

            'comment': 'these games suit everyone',

            'mine_id': mine_id

             }

或?qū)⒘斜硖砑拥胶灻?,它將起作?)。


查看完整回答
反對(duì) 回復(fù) 2022-01-18
  • 1 回答
  • 0 關(guān)注
  • 362 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)