Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Flask、Marshmallow 3和webargs使用\ args无法解析参数_Python_Flask_Marshmallow_Webargs - Fatal编程技术网

Python Flask、Marshmallow 3和webargs使用\ args无法解析参数

Python Flask、Marshmallow 3和webargs使用\ args无法解析参数,python,flask,marshmallow,webargs,Python,Flask,Marshmallow,Webargs,在Flask 1.1.2、marshmallow 3.6.1和webargs 6.1.0中,我所有的参数总是缺失 模式: class ExportSearchSchema(Schema): limit = fields.Integer(required=False, allow_none=False, default=10, missing=10) offset = fields.Integer(required=False, allow_none=False, default=

在Flask 1.1.2、marshmallow 3.6.1和webargs 6.1.0中,我所有的参数总是
缺失

模式:

class ExportSearchSchema(Schema):
    limit = fields.Integer(required=False, allow_none=False, default=10, missing=10)
    offset = fields.Integer(required=False, allow_none=False, default=0, missing=0)
    status = fields.Str(required=False)

    class Meta:
        unknown = RAISE

    @validates('status')
    def validate_status(self, value):
        if value and value not in ['complete', 'pending', 'failed']:
            raise ValidationError('Invalid status: {}'.format(value))

    @validates('limit')
    def validate_limit(self, value):
        if value > 100:
            raise ValidationError('Max limit is 100')
        if value < 1:
            raise ValidationError('Limit must be a positive number and less than 100')

    @validates('offset')
    def validate_offset(self, value):
        if value < 0:
            raise ValidationError('Offset must be equal to, or greater than 0')

当我为
limit
offset
卷曲任何值时,它总是使用
默认值

curlhttp://localhost:8000/exports?limit=5930

log:“qparams{'limit':10,‘offset':0}”}

我希望提高
ValidationError
,因为限制应该大于100

当我卷曲一个未知参数时,我希望引发一个
ValidationError
,因为它是一个未知参数。这也没有达到预期效果

curlhttp://localhost:8000/exports?lkfjdskl=fkjdsl

返回一个200并且没有
qparams


webargs
Flask
marshmallow
组合在一起,我做错了什么?

webargs 6中的逻辑发生了变化

在webargs 6之前,解析器将迭代模式的字段,并在默认情况下搜索多个位置以查找值

在webargs 6中,解析器只是将数据从单个位置传递到模式。该位置默认为
“json”

由于使用的是查询参数,因此需要显式指定:

@use_args(ExportSearchSchema(unknown=RAISE), location="query")
因为您没有指定位置,所以假定json主体,没有找到任何内容,并使用默认值

这记录在webargs文档中:

@use_args(ExportSearchSchema(unknown=RAISE), location="query")