Questions tagged [webargs]

webargs is a Python library for parsing HTTP request arguments, with built-in support for popular web frameworks, including Flask, Django, Bottle, Tornado, and Pyramid.

webargs is a friendly library for parsing HTTP request arguments, with built-in support for popular web frameworks, including Flask, Django, Bottle, Tornado, and Pyramid.

30 questions
6
votes
2 answers

flask-marshmallow: how to mark all fields as optional only when the method is PUT

I am making a flask restful API, what I'm having trouble with is marshmallow-sqlalchemy, and webargs. In short here is my sqlalchemy model: class User(Model): id = Column(String, primary_key=True) name = Column(String(64), nullable=False) …
RRR
  • 513
  • 2
  • 6
  • 14
4
votes
2 answers

How to parse a multipart form-data that contains both files and normal fields in webargs?

I need to parse a multipart form-data with attached file using webargs. At this moment I have the next model: RAW_ARGS = { 'file': fields.Field( required=True, validate=lambda file: file.mimetype ==…
Denis Sologub
  • 7,277
  • 11
  • 56
  • 123
4
votes
2 answers

Can webargs / Marshmallow in Python modify a field, not just validate it?

I'm using Flask with flask-restful and webargs (which uses Marshmallow as its backend). Currently I'm able to pull in fields I want with this: class AddGroup(Resource): args = { 'name': fields.Str(missing=None), 'phone':…
David White
  • 1,763
  • 2
  • 16
  • 27
3
votes
1 answer

flask-apispec not populating kwargs with values from GET query (implementation of example code from documentation)

I am using flask-apispec with webargs to define the types of a simple API. I have produced a minimal example, below, that reproduces the issue, which is that the kwargs object is empty. Server code: import flask from flask_apispec import…
Ian Fiddes
  • 2,821
  • 5
  • 29
  • 49
3
votes
1 answer

Flask error handler not able to handle Assertion Error

I am using Flask-RESTful for building REST api and webargs for parsing. While defining resource, I want argument to be present, so I wrote required=True For example: class Name(Resource): """Retrieve ids corresponding to given names Input entries:…
navrocks
  • 31
  • 5
2
votes
1 answer

Unable to validate list of dicts using marshmallow Schema with webargs use_kwargs - Error 422 Unprocessable Entity

I have the following endpoint in Flask: from flask import Flask from marshmallow import EXCLUDE, Schema, fields from webargs.flaskparser import use_kwargs app = Flask( __name__, static_url_path="", static_folder="static",…
vvvvv
  • 25,404
  • 19
  • 49
  • 81
2
votes
1 answer

webargs got exception when validate args

recently I got some problems when I using webargs(8.0.1) and flask-restful(0.3.8) the exception throw twice when I try to use cURL http://127.0.0.1:5001/?score=100A I think it supposed to be return a jsonfy error message with function…
Ciao
  • 21
  • 1
2
votes
1 answer

Flask, Marshmallow 3, and webargs use_args fails to parse arguments

With Flask 1.1.2, marshmallow 3.6.1 and webargs 6.1.0 all of my arguments are always missing. Schema: class ExportSearchSchema(Schema): limit = fields.Integer(required=False, allow_none=False, default=10, missing=10) offset =…
Denise Mauldin
  • 5,397
  • 5
  • 32
  • 51
2
votes
1 answer

Validate Variable Parameters In URL Path and Query Parameters using Webargs Flaskparser

I'm trying to validate all data being sent to my api. My url structure contains a variable within it, /api/v2/users//collections/, as well as actual query string parameters, all of which need to be passed through validation. The…
stwhite
  • 3,156
  • 4
  • 37
  • 70
2
votes
1 answer

Python Flask Flasgger (Swagger) webargs - List of Strings in HTTP PUT body

I've created a python web API using flask, flasgger (swagger defined by yml files), and webargs: @app.route('/api/set/', methods=['PUT']) @swag_from('swagger/put_community_sets.yml') @use_kwargs({'community_set': fields.List(fields.Str(), …
mlander
  • 51
  • 5
2
votes
1 answer

How to pass arguments to webargs method directly from code without http call?

I have Flask method that workd perfectly via HTTP: class PricePerPeriod(Resource): args = {'period': fields.Int(required=True, validate=lambda val: val > 0), 'duration': fields.Int(required=True, validate=lambda val: val > 0)} …
uzla
  • 515
  • 1
  • 4
  • 20
1
vote
1 answer

Using a custom parser with flask_smorest and/or marshmallow

I'm using flask-smorest, the Flask/Marshmallow-based REST API framework and would like to be able to parse requests made with the axios JavaScript library, specifically for arrays passed via the querystring. Axios sends arrays like…
Mathieu Dhondt
  • 8,405
  • 5
  • 37
  • 58
1
vote
1 answer

GET params are not recieved in Flask-RESTful + webargs

I'm using Resource class from flask restful and use_kwargs decorator for get method. Here is the code: @api.resource('/route/') class API(Resource): @use_kwargs({'param': fields.Str(missing='default_val')} def get(self, param): …
Dmitry Sazhnev
  • 383
  • 3
  • 16
1
vote
1 answer

Parse delimited and nested field names from URL parameter for partial response

In a Flask-RESTful based API, I want to allow clients to retrieve a JSON response partially, via the ?fields=... parameter. It lists field names (keys of the JSON object) that will be used to construct a partial representation of the larger…
rypel
  • 4,686
  • 2
  • 25
  • 36
1
vote
0 answers

How to add apispec for post method in flask MethodView?

I have the following packages in my project: 1. flask (webframework) 2. webargs and marshmallow for request and response definition 3. apispec and apispec-webframework.flask for generation of openapi 3.0 doc. Our project has chosen to use MethodView…
is_slo_and
  • 11
  • 2
1
2