Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
Hi guys, Hope everyone is well and safe! Thanks for this awesome tool! I really enjoy using it. Quick question, is there a way to return a 200 status code with a status message and the json response body? I know there is a way for errors/aborts etc. Just wondering... Got an issue where the POST was performed but I need a warning message to be displayed.
Matt Flaherty
Hi @Justvuur. I may be misunderstanding, but returning a custom message with a status code is simple. There is a parameter for description in the @api.response() and and optional one in @api.marshal_with() decorators. See the following example from the documentation:
class MyResource(Resource):
    @api.response(400, 'Validation error')
    @api.marshal_with(model, code=201, description='Object created')
    def post(self):
Hello all. A few of you know me. I've contributed a little bit of code to flask-restplus in the past. I would like to contribute more to this project now and I have time on my hands since I've been furloughed from my job. Please let me know of anything in particular that needs doing or I'm happy to join a major rewrite effort. Thanks.
David Cannings
This message was deleted
Guto Maia

Hi @Justvuur, i'm facing some error on trying to create a Polymorph List in the response of a service (ex: fields.List(fields.Polymorph(mapping))).

parent_fields = {
    'index': fields.Integer(description='index')

parent = ns.model('Parent', parent_fields)

child1_fields = {
    'attr': fields.String(required=True, description='attr'),

child1 = parent.inherit('Child1', child1_fields)

child2_fields = {
    'attr': fields.String(required=True, description='attr'),

child2 = parent.inherit('Child2', child2_fields)

mapping = {
    child1: child1_fields,
    child2: child2_fields,


That gives a TypeError " TypeError: unhashable type: 'Model'".

Guto Maia
hi @noirbizarre
Nitendra Singh Yadav
hi @all, is there any good library in python for users and subscription management?
@flayman Thanks but would it be possible to change the messing in the method/function depending on the case/outcome?
Matt Flaherty
@Justvuur, it's trivial if you want to use a different status code for each outcome. You register each response. If you want to use the same code and different messages, then it doesn't make sense to document them
Nitendra Singh Yadav
class ObjectIdVal(fields.Raw):
schema_type = 'string'
schema_example = '54f0e5aa313f5d824680d'
def format(self, id):
x = bson.objectid.ObjectId.is_valid(id)
return x
except ValueError as ve:
raise MarshallingError(ve)
def validate(self, id):
Validate the value. return True if valid
return False
hey @noirbizarre , I am unable to get any value in print when adding a field in my model, also its not validating a input string as per the code in format method

Hey there users and devs, thanks for RestPlus which is an awesome Flask module.

It seems like an @property method can't be formatted by Marshal as the JSON key returns null, is this correct?

Python Hub

Hey, guys, I need your help, I have a class which consists of all my error
class InternalServerError(Exception):

class SchemaValidationError(Exception):

class UpdatingUserError(Exception):

class UserNotExistsError(Exception):

class EmailAlreadyExistsError(Exception):

class UnauthorizedError(Exception):

errors = {
"InternalServerError": {
"message": "Something went wrong",
"status": 500
"SchemaValidationError": {
"message": "Request is missing required fields",
"status": 400
"UpdatingUserError": {
"message": "Updating user data is forbidden",
"status": 403
"UserNotExistsError": {
"message": "The user is not registered",
"status": 400
"EmailAlreadyExistsError": {
"message": "User with given email address already exists",
"status": 400
"UnauthorizedError": {
"message": "Invalid username or password",
"status": 401
How can I add this to my API

How can I do this, In flask-restful I have an option to add a class of errors but in restx I don't know how to do that.
John Chittum
if asking about restx, go here: https://gitter.im/python-restx/community
Hi, I'm using @api.resource decorator for endpoint routing in Flask, what I'm not able to figure out is how to accept some parameter in one of the resource methods only (e.g. def get(self, task_id)). Is there any other way other than using api.add_resource... ? Thanks
Akanksha Jain
Hi @all, I am trying Flask-restplus, gunicorn on Docker. Locally endpoint works. But with Docker endpoint always giving 404 error within container as well as directly with endpoint.
Any suggestion or anything which I can check. I tried all the available options posted on google. But nothing is working
No error message nothing in the logs .
[2020-10-28 10:29:58 +0000] [1] [INFO] Starting gunicorn 20.0.4
[2020-10-28 10:29:58 +0000] [1] [INFO] Listening at: (1)
[2020-10-28 10:29:58 +0000] [1] [INFO] Using worker: sync
[2020-10-28 10:29:58 +0000] [7] [INFO] Booting worker with pid: 7
[2020-10-28 10:42:04 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:7)
[2020-10-28 10:42:04 +0000] [8] [INFO] Booting worker with pid: 8
Akanksha Jain
DockerFile config

FROM python:3.8-slim-buster



ADD requirements.txt .
RUN python -m pip install -r requirements.txt

ADD . /app

RUN useradd appuser && chown -R appuser /app
USER appuser

CMD ["gunicorn", "--bind", "", "app:app"]

requirement file only having this
Any help please.
Ugur B.
when do we need to register/create a model through a Namespace and not through an API? I only use models with the marshal_with decorator and it takes the instance as the argument. Are we require to register the model first to be able to use it in the decorator?
Henshal B
is there any option to add tags for flask-restplus, swagger docs?
Hi guys
is there an opposite function of flask_resplus.abort
@henshalb use Namespace
Narate Pokasub
I try to use flask_limit with flask_resplus. So anyone can suggest the example or document that support namespace
I tried to implement my flask-restplus program but i couldn't even access restplus import and throwing the following error
Traceback (most recent call last):
File "D:\crudapi\app.py", line 2, in <module>
from flask_restplus import Api
File "D:\crudapi\venv\lib\site-packages\flask_restplus__init.py", line 4, in <module>
from . import fields, reqparse, apidoc, inputs, cors
File "D:\crudapi\venv\lib\site-packages\flask_restplus\fields.py", line 17, in <module>
from werkzeug import cached_property
ImportError: cannot import name 'cached_property' from 'werkzeug' (D:\crudapi\venv\lib\site-packages\werkzeug\
pip freeze
Anyone help me to solve the issue
Anik Chowdhury
Screenshot 2021-06-02 at 10.53.32 AM.png
I am newbie in flask and flask rest api. Can anyone suggest how to implement this dropdown like this in swagger?
Henshal B
@bala4604: you've to activate the virtual environment first
Or downgrade Werkzeug
Or switch to flask restx
Hello, is possible to configure fields with required tag to not accept empty values?
Giacomo Gritzan
Hello everyone, I am trying to export the swagger.json file for my flask-restplus api to generate a corresponding api-client via swagger-codegen. In the documentation there is a command how to export the schema of the api but not where to place this export. Can anyone tell me the best place to place the export?
Drei Quevada
Hello everyone. This might be trivial to some but has anyone implemented a stable implementation to filter model fields that we only want to use, let's say from a page? For example, I have a flask model (SQLAlchemy) of Person with fields: name, age, birthdate, group . I would like to send a request that has a params data for the fields that I only want to get from a Person model (e.g. name and group). It's easy to implement for unnested fields but for example, I further want to specify the fields that I want for the group field (e.g. I only want the group ID). I'm not asking for a code, rather a stable structure/architecture on how to implement this. Thank you for the help!