最新消息:20210917 已从crifan.com换到crifan.org

[已解决]flask request get_json None

Python crifan 7602浏览 0评论
搜:
flask request get_json None
参考:
 return jsonify(request.get_json(force=True))
   content = request.get_json(silent=True)
If the mimetype is application/json this will contain the parsed JSON data. Otherwise this will be None.
get_json(force=False, silent=False, cache=True)
Parses the incoming JSON request data and returns it. If parsing fails the on_json_loading_failed() method on the request object will be invoked. By default this function will only load the json data if the mimetype is application/json but this can be overridden by the force parameter.
Parameters:
force – if set to True the mimetype is ignored.
silent – if set to True this method will fail silently and return None.
cache – if set to True the parsed JSON data is remembered on the request.
on_json_loading_failed(e)¶
Called if decoding of the JSON data failed. The return value of this method is used by get_json() when an error occurred. The default implementation just raises a BadRequest exception.
Changed in version 0.10: Removed buggy previous behavior of generating a random JSON response. If you want that behavior back you can trivially add it by subclassing.
New in version 0.8.
-》
加上:
force=True
变成:
request.get_json(force=True)
即可。

转载请注明:在路上 » [已解决]flask request get_json None

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.184 seconds, using 23.34MB memory