You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am creating a Flask Rest API using Flask RestPlus framework. In that I am trying to integrate the Flask Profiler and while running the api, it throws the following error. If I remove the Profile decorator it works fine but does not profile the resource.
TypeError: Object of type 'Resource' class is not JSON serializable
Below is the complete code. Can someone help me on this.
from flask import Flask, jsonify
from flask_restplus import Resource, Api
import flask_profiler as profiler
import json
app = Flask(__name__)
api = Api(app)
app.config["flask_profiler"] = {
"enabled": True,
"storage": {
"engine": "sqlite",
"file": "profiler.sqlite"
},
"basicAuth":{
"enabled": True,
"username": "admin",
"password": "admin"
},
"ignore": [
"^/static/.*"
]
}
profiler.init_app(app)
convert_obj_to_json_dict = lambda obj: obj.__dict__
class Person:
def __init__(self, firstname, lastname):
self.first_name = firstname
self.last_name = lastname
def toJSON(self):
return convert_obj_to_json_dict(self)
@api.route('/persons')
class PersonResource(Resource):
@profiler.profile()
def get(self):
persons = []
persons.append(Person("John", "Doe"))
persons.append(Person("Harry", "Walter"))
return [convert_obj_to_json_dict(person) for person in persons]
if __name__ == '__main__':
app.run(port=6000)
The text was updated successfully, but these errors were encountered:
I am creating a Flask Rest API using Flask RestPlus framework. In that I am trying to integrate the Flask Profiler and while running the api, it throws the following error. If I remove the Profile decorator it works fine but does not profile the resource.
Below is the complete code. Can someone help me on this.
The text was updated successfully, but these errors were encountered: