'Unable to retrieve attribute 'objval'

Hoping someone could give me a hand, I am having issues retrieving an optimal value for my code as shown below. I have found that the status code is 2 which indicates it can be solved and there is an optimal value, I am just unsure why it cannot give me that value. Please Help, this is a big assignment & I am struggling a lot!.

`mod = gp.Model('Gladstone')
mod.setParam('LogToConsole', 0)
mod.setParam('OutputFlag', 0)


N_investors = 2000
   #Add variables
    
#cost of telephone for each group
t = {1: 15, 2:12, 3:20, 4:18}
#cost of personal for each group
p = {1: 35, 2:30, 3:50, 4:40}
group = [1,2,3,4]

x = mod.addVars(groups, lb=0, vtype=GRB.CONTINUOUS, name = 'personal_group') #number of people contacted in person in group i
y = mod.addVars(groups, lb=0, vtype=GRB.CONTINUOUS, name = 'telephone_group')#number of people contacted in telephone in group i

#Constraints
mod.addConstr((gp.quicksum(x[i] + y[i])for i in groups) == N_investors)
mod.addConstr((x[1] + x[2] + y[1] + y[2]) >= (N_investors))
mod.addConstr((x[1] + x[2] + x[3] + x[4]) >= (0.25 * N_investors))
mod.addConstr((x[1] + x[2] + x[3] + x[4]) >= (0.5* (x[1] + y[1])))
mod.addConstr((x[2] + y[2] + x[4] + y[4])  <=(0.4 * N_investors))
mod.addConstr((x[1] + x[2] + x[3] + x[4] <= (0.25 * (x[2] + y[2] + x[4] + y[4]))))
mod.addConstr((x[1] + y[1]) >= (0.1 * N_investors))
mod.addConstr(((x[2] + y[2])) >= (0.1 * N_investors))
mod.addConstr(((x[3] + y[3])) >= (0.1 * N_investors))
mod.addConstr(((x[4] + y[4])) >= (0.1 * N_investors))
mod.addConstr(((x[1] + y[1])) <= (0.5 * N_investors))
mod.addConstr(((x[2] + y[2])) <= (0.5 * N_investors))
mod.addConstr(((x[3] + y[3])) <= (0.5 * N_investors))
mod.addConstr(((x[4] + y[4])) <= (0.5 * N_investors))

#Objective
costs = (t[1] * y[1]) + (t[2] * y[2]) + (t[3] * y[3])  + (t[4] * y[4]) + (p[1] * x[1]) + (p[2] * x[2]) + (p[3] * x[3]) + (p[4] * x[4])
mod.setObjective(costs, sense = GRB.MINIMIZE)  

mod.update()
mod.optimize()

print(mod.objval)`



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source