sqlalchemy.exc.ArgumentError: List argument must consist only of tuples or dictionaries

Viewed 21

I try to push some data to my DB with fastapi, ive seen people having similar problems to mine i tried to use the solutions but nothing works on me.

   @app.post("/user")
async def create_user(username, pseudo, email, password, db: _orm.Session = fastapi.Depends(_services.get_db)):
    statement = "INSERT INTO user(username, pseudo, email, password) VALUES(?, ?, ?, ?)"
    db.execute(statement, [username, pseudo, email, password])
    db.commit()
    return True

When i try that i get this error

sqlalchemy.exc.ArgumentError: List argument must consist only of tuples or dictionaries

And when i try this code

   @app.post("/user")
async def create_user(username, pseudo, email, password, db: _orm.Session = fastapi.Depends(_services.get_db)):
    statement = "INSERT INTO user(username, pseudo, email, password) VALUES(?, ?, ?, ?)"
    db.execute(statement, (username, pseudo, email, password))
    db.commit()
    return True

I got this error

sqlalchemy.exc.ProgrammingError: (sqlite3.ProgrammingError) Incorrect number of bindings supplied. The current statement uses 4, and there are 0 supplied. [SQL: INSERT INTO users(username, pseudo, email, password) VALUES(?, ?, ?, ?)]

0 Answers
Related