This code works perfectly but sometimes I’m getting the below error, how to fix this.
'''cursor_variable_insert.execute(qa_patchstatusupdate_query, qa_deploymentstatusupdate_values)
File "/usr/lib64/python3.9/site-packages/psycopg2/extras.py", line 251, in execute
return super(RealDictCursor, self).execute(query, vars)
IndexError: tuple index out of range'''
Below is the code block:
for row in cursor_variable:
print(row[0],row[-1])
qa_server_names = row[0]
qa_compliant_status = row[-1]
qa_deploymentstatusupdate_query = "UPDATE masterinventory SET deploymentstatus=%s
WHERE servername ILIKE %s"
qa_deploymentstatusupdate_values = (qa_compliant_status, qa_server_names)
cursor_variable_insert.execute(qa_deploymentstatusupdate_query,
qa_deploymentstatusupdate_values)
qa_patchstatusupdate_query = "UPDATE masterinventory SET patchstatus = (case when
deploymentstatus not like '%Compliant%' then 'Non-Compliant' when
deploymentstatus='Compliant' then 'Compliant' end) WHERE servername ILIKE '%%s%'"
qa_patchstatusupdate_values = [(qa_server_names,)]
cursor_variable_insert.execute(qa_patchstatusupdate_query,
qa_deploymentstatusupdate_values)
connection.commit()