Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Restful API Python Flask Postman
#1
already since 1 week I try to build a simple CRUD RESTful API without success. So when I create/(test) user and post in the cmd I can list them (User.query.all()) but when I try to get all users via my function get_all_users() I get this error: TypeError: 'Engine' object is not callable
Here's my user data model.
#modules importieren

# Create Flask app
app = Flask(__name__)

# Flask-SQLAlchemy settings
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' # File-based SQL database
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Avoids SQLAlchemy warning

# Initialize Flask-SQLAlchemy
db = SQLAlchemy(app)

# Initialize Flask-API
api = Api(app)

# Import routes
from webapp import routes
models.py
class User(db.Model, UserMixin):
    
   # __tablename__ = 'user' (habe auch damit versucht aber ändert sich nicht)

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20), nullable=False, default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref='author', lazy=True)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
in routes.py
@app.route('/api/users/', methods = ['GET'])
def get_all_user():
    
    engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
    
    conn = engine.connect()
    
    #metadata = db.Metadata()
    
    user = db.engine('user', autoload=True, autoload_with=engine, engine_options=None)

    req = db.select([user])
    
    result = conn.execute(req)
    
    row_result = result.query.all()
    
    return jsonify(row_result)

    conn.close()
in Postman with the URL : http://127.0.0.1:5000/api/users/
I get this error message : TypeError: 'Engine' object is not callable // Tool Debugger

Thank you for your help

B. regards
Karl
Reply


Messages In This Thread
Restful API Python Flask Postman - by starter_student - Sep-19-2019, 07:12 AM
RE: Restful API Python Flask Postman - by ndc85430 - Sep-22-2019, 08:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python3 - How to deny access to users without api key using localhost and postman Alan2023 0 980 Feb-20-2023, 02:50 PM
Last Post: Alan2023
  Creating a RESTful web service and web service client dangermaus33 0 1,300 Dec-01-2020, 09:56 PM
Last Post: dangermaus33
  python 3.7 on windows using flask and flask-sqlalchemy. Alpy 2 4,028 Aug-12-2020, 07:24 PM
Last Post: Alpy
  RESTful API in Google Cloud Functions fggmack 0 2,028 Dec-30-2018, 06:58 AM
Last Post: fggmack

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020