Could you someone help me to resolve KeyError while I am running a service ? i.e something related to consul

if self.connection.agent.checks()[self.check_id]['Status'] == 'critical':

KeyError: u’13456@uhn3snm2esfe0006.rmn.local:9095’
2023-10-19 15:17:25,223: INFO: on_error: [[‘stop’]]
2023-10-19 15:17:25,223: INFO: on_error: [‘stop’]

You’re receiving this error because the agent that you’re querying does not have a check with this check ID.

Without having more info on how you are obtaining self.check_id, its difficult to say whether this is an issue with Consul not returning details for a valid check ID, or whether the check is not present at all on the agent.

If you want to more gracefully handle the error condition, you could change the code to something like this.

registered_agent_checks = self.connection.agent.checks()
if self.check_id not in registered_agent_checks:
   # Raise or log error about check not being present on the machine.

if registered_agent_checks[self.check_id]['Status'] == 'critical':