简体   繁体   English

来自 reqparse flask_Restful 的 parse_args 返回错误

[英]parse_args from reqparse flask_Restful returning error

I'm using flask_restful and using reqparse to get params as an example:我正在使用 flask_restful 并使用 reqparse 来获取参数作为示例:

from flask_restful import Resource, reqparse

path_params = reqparse.RequestParser()
path_params.add_argument("city", type=str)
path_params.add_argument("star_min", type=float)
path_params.add_argument("star_max", type=float)
path_params.add_argument("diary_max", type=float)
path_params.add_argument("diary_min", type=float)
path_params.add_argument("limit", type=float)
path_params.add_argument("offset", type=float)

       data = path_params.parse_args()
// returning error here : "message": "Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)"

What can I do to solve this, please?请问我该怎么做才能解决这个问题?

What you are seeing is the error when json.load or ( json.loads ) receives an empty JSON document to decode.您看到的是json.load或 ( json.loads ) 收到空的 JSON 文档进行解码时出现的错误。

import json

json.loads("")
# raises JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Without more of your code and especially request you sent, we cannot tell you more about your problem.如果没有您的更多代码,尤其是您发送的请求,我们无法告诉您更多有关您的问题的信息。

But, if I run the full example from the Flask-RESTful docs and request an empty JSON doc, I get the same error.但是,如果我运行 Flask-RESTful 文档中的完整示例并请求一个空的 JSON 文档,我会得到同样的错误。

curl http://localhost:5000/todos -H "Content-Type: application/json" -d '' -X POST
{
    "message": "Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)"
}

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

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