我正在尝试使用参数中的字典来调用存储过程来更新将Dict中的值用作外键的表。
Dict数据(ID是外键),例如: 服务器1,ID1 server5,ID2
ID是我尝试更新的表上的外键,并且在调用存储过程时需要作为参数。看来,当我将字典作为参数传递时,它将拉动server1而不是ID1并导致键错误。
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]
跟踪:guardpointparams =(row ['FS代理程序注册状态'],第['FS代理程序版本'],第['Guard路径'],serverdict [row ['主机名']],policydict [row [ [政策名称]]],0) KeyError:“ server1”
答案 0 :(得分:2)
row['Host Name']
似乎是server1
。字典serverdict
没有名为server1
答案 1 :(得分:0)
您的serverdict
或policydict
似乎没有定义。至少您没有在示例中提供定义。此外,回溯告诉您其中之一没有您要查找的密钥。