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

在使用flask-restfull进行API开发的时候。一旦我使用类似下面的代码从url或者form中获得参数就会出现报错:Did not attempt to load JSON data because the request Content-Type was not ‘application/json’。
代码如下:

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)

解决方法如下

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

猜你喜欢

转载自blog.csdn.net/aofengdaxia/article/details/130576773