unexpected keyword argument in execute statement

Question:

def add_application_to_db(job_id, data):
    with engine.connect() as conn:
        sql = text(
            "INSERT INTO application(id,job_id,fullname,email,linkedin,education,experience,resumeurl) VALUES (:job_id,:fullname,:email,:linkedin,:education,:experience,:resumeurl)"
        )
        conn.execute(
            job_id=job_id,
            fullname=data["fullname"],
            email=data["email"],
            linkedin=data["linkedin"],
            education=data["education"],
            experience=data["experience"],
            resumeurl=data["resumeurl"],
        )

I am learning flask and using MySQL and sqlalchemy.I am trying to store info from user into the data base (table name = application)
I got following error

TypeError: Connection.execute() got an unexpected keyword argument ‘job_id’

Asked By: vikash

||

Answers:

If you are using SQLAlchemy 2.0 then you have to send the parameters as a dict instead of what you are trying now.

def add_application_to_db(job_id, data):
    row = {
        "job_id": job_id,
        "fullname": data["fullname"],
        "email": data["email"],
        "linkedin": data["linkedin"],
        "education": data["education"],
        "experience": data["experience"],
        "resumeurl": data["resumeurl"],
    }
    with engine.connect() as conn:
        sql = text(
            "INSERT INTO application(id,job_id,fullname,email,linkedin,education,experience,resumeurl) VALUES (:job_id,:fullname,:email,:linkedin,:education,:experience,:resumeurl)"
        )
        conn.execute(sql, row)
Answered By: python_user
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.