I am trying to use the dictionary in a parameter to call a stored procedure to update a table that uses a value in the Dict as a foreign key.
Dict data (ID is the foreign key) ex: server1, ID1 server5, ID2
ID is the foreign key on the table i am trying to update and needs to be the parameter when calling the stored procedure. It appears that when i pass in the dictionary as a parameter it is pulling server1 instead of ID1 and causing a key error.
with open('DBstatus.csv') as dbcsvfile:
dbstatus = csv.DictReader(dbcsvfile)
for row in dbstatus:
#Create parameters for stored procedure
guardpointparams = (row['FS Agent Registration Status'], row['FS Agent Version'], row['Guard Path'], serverdict[row['Host Name']], policydict[row['Policy Name']], 0)
#call stored procedure
updateguardpointstable = cursor.callproc('update_guardpoints', guardpointparams)
#i created the dictionary from a different script while updating the
"servers" table where the DB is creating the returnvalue (ID) from the
stored procedure see sample below:
serverdict[row['Host Name']] = returnvalue[3]
Traceback: guardpointparams = (row['FS Agent Registration Status'], row['FS Agent Version'], row['Guard Path'], serverdict[row['Host Name']], policydict[row['Policy Name']], 0) KeyError: 'server1'
row['Host Name']
appears to be server1
. The dictionary serverdict
does not have a key named server1