Did not attempt to load JSON data because the request Content-Type was not ‘application/json‘

When using flask-restfull for API development. Once I use code similar to the following to get parameters from url or form, an error will appear: Did not attempt to load JSON data because the request Content-Type was not 'application/json'.
code show as below:

from flask_restful import reqparse
parser = reqparse.RequestParser()
parser.add_argument("page", type=int)
parser.add_argument("limit", type=int)

class IndustryListResource(Resource):
    def get(self):
        args = parser.get_page_parser()
        records = Industry.query.order_by(Industry.id).all()
        return Result.list_result(records)

The solution is as follows

# 增加location的来源
parser.add_argument("page", type=int, location="args")

Guess you like

Origin blog.csdn.net/aofengdaxia/article/details/130576773