简体   繁体   English

在烧瓶中返回现有的 JSON 文件

[英]return existing JSON file in flask

i have a method ( matching ) that returns a JSON file.我有一个返回 JSON 文件的方法( matching )。 I want to return this file via a flask method.我想通过烧瓶方法返回这个文件。

when i do this:当我这样做时:

@app.route('/search', methods=['POST'])
def json_example():
    req_data = request.get_json()
    request_text = req_data['request'] #json text that is needed as argument for calling the matching method
    json_result = matching(request_text)
    return json_result

i get this error:我收到此错误:

<title>TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple,
    Response instance, or WSGI callable, but it was a TextIOWrapper. // Werkzeug Debugger</title>

playing around with str(json_result ), i just get this:玩弄str(json_result ),我得到了这个:

<_io.TextIOWrapper name='result.json' mode='w' encoding='UTF-8'>

Also, jsonify(json_reslult) does not work, since i have a json file and am not trying to convert a string into a json.此外, jsonify(json_reslult)不起作用,因为我有一个 json 文件并且我没有尝试将字符串转换为 json。 when trying it gives:尝试时它给出:

<title>TypeError: Object of type TextIOWrapper is not JSON serializable // Werkzeug Debugger</title>

Any helpis greatly appreciated任何帮助是极大的赞赏

首先解码 request_text

json_result = matching(json.loads(request_text))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM