Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Matt Flaherty
@flayman
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:
@api.route('/my-resource/')
class MyResource(Resource):
    @api.response(400, 'Validation error')
    @api.marshal_with(model, code=201, description='Object created')
    def post(self):
        pass
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
@dc_pwc_gitlab
This message was deleted
Guto Maia
@gutomaia

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,
}


fields.List(fields.Polymorph(mapping))

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

Guto Maia
@gutomaia
hi @noirbizarre
Nitendra Singh Yadav
@nitendra-yadav
hi @all, is there any good library in python for users and subscription management?
Justvuur
@Justvuur
@flayman Thanks but would it be possible to change the messing in the method/function depending on the case/outcome?
Matt Flaherty
@flayman
@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
@nitendra-yadav
{{{
class ObjectIdVal(fields.Raw):
schema_type = 'string'
schema_example = '54f0e5aa313f5d824680d'
def format(self, id):
try:
x = bson.objectid.ObjectId.is_valid(id)
print(x)
return x
except ValueError as ve:
raise MarshallingError(ve)
def validate(self, id):
"""
Validate the value. return True if valid
"""
print(id)
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
bkranendonk
@bkranendonk

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
@pythonhubpy

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

class SchemaValidationError(Exception):
pass

class UpdatingUserError(Exception):
pass

class UserNotExistsError(Exception):
pass

class EmailAlreadyExistsError(Exception):
pass

class UnauthorizedError(Exception):
pass

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
@j5awry
if asking about restx, go here: https://gitter.im/python-restx/community
chama-chomo
@chama-chomo
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
@ankajain
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: http://0.0.0.0:5001 (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
@ankajain
DockerFile config

FROM python:3.8-slim-buster

EXPOSE 5001

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

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

WORKDIR /app
ADD . /app

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

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

requirement file only having this
flask==1.1.2
gunicorn==20.0.4
flask-restplus==0.13.0
Any help please.
Ugur B.
@ayakzob
hi,
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
@henshalb
is there any option to add tags for flask-restplus, swagger docs?
realburi
@realburi
Hi guys
is there an opposite function of flask_resplus.abort
tankeryang
@tankeryang
@henshalb use Namespace
Narate Pokasub
@narate.pokasub_gitlab
I try to use flask_limit with flask_resplus. So anyone can suggest the example or document that support namespace
Balaji
@bala4604
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\
init__.py)
pip freeze
aniso8601==9.0.1
attrs==21.2.0
click==8.0.1
colorama==0.4.4
Flask==2.0.1
flask-restplus==0.13.0
itsdangerous==2.0.1
Jinja2==3.0.1
jsonschema==3.2.0
MarkupSafe==2.0.1
pyrsistent==0.17.3
pytz==2021.1
six==1.16.0
Werkzeug==2.0.1
Anyone help me to solve the issue
Anik Chowdhury
@nikitow1
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
@henshalb:matrix.org
[m]
@bala4604: you've to activate the virtual environment first
Or downgrade Werkzeug
Or switch to flask restx
MiguelMachadoCodeone
@MiguelMachadoCodeone
Hello, is possible to configure fields with required tag to not accept empty values?
fields.String(required=True)
Giacomo Gritzan
@ggritzan_gitlab
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
@dreiq-codev
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!