[英]return existing JSON file in flask
我有一個返回 JSON 文件的方法( matching
)。 我想通過燒瓶方法返回這個文件。
當我這樣做時:
@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
我收到此錯誤:
<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>
玩弄str(json_result
),我得到了這個:
<_io.TextIOWrapper name='result.json' mode='w' encoding='UTF-8'>
此外, jsonify(json_reslult)
不起作用,因為我有一個 json 文件並且我沒有嘗試將字符串轉換為 json。 嘗試時它給出:
<title>TypeError: Object of type TextIOWrapper is not JSON serializable // Werkzeug Debugger</title>
任何幫助是極大的贊賞
首先解碼 request_text
json_result = matching(json.loads(request_text))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.