Home > Back-end >  TypeError: 'Employee' object is not callable
TypeError: 'Employee' object is not callable

Time:12-21

I have a class

class Employee(BaseModel):
    Emp_ID: int
    Emp_Name: str
    Emp_Qualification: str

and below is code for POST request, i am getting error in last return where i was trying to get employee["Emp_id"] value.

@app.api_route("/post-details/{postid}", methods=["POST"])        
def post(postid: int , employee : Employee):
        newlist = []
        cursor=conn.cursor()
        getemploy2= "select id from employee3"
        cursor.execute(getemploy2)
        result = cursor.fetchall()
        for list in result:
                newlist.extend(list)
        if postid in newlist:
                return "yes it exist"
        return employee(["Emp_ID"])

CodePudding user response:

You can access an object's attribute with the . operator:

return employee.Emp_ID
  • Related