diff --git a/zabbix/zabbix_api.py b/zabbix/zabbix_api.py index 87ccae9..3344a1b 100644 --- a/zabbix/zabbix_api.py +++ b/zabbix/zabbix_api.py @@ -276,9 +276,23 @@ def do_request(self, json_obj): self.id += 1 if 'error' in jobj: # some exception + if not jobj['error'].has_key('code'): + msg = 'response does not contains error->code key"' + self.debug(logging.ERROR, msg) + raise ZabbixAPIException(msg) + if not jobj['error'].has_key('message'): + msg = 'response does not contains error->message key"' + self.debug(logging.ERROR, msg) + raise ZabbixAPIException(msg) + tmp_data = "" + if not jobj['error'].has_key('data'): + msg = 'response does not contains error->data key"' + self.debug(logging.INFO, msg) + else: + tmp_data = jobj['error']['data'] msg = "Error %s: %s, %s while sending %s" % (jobj['error']['code'], - jobj['error']['message'], jobj['error']['data'], str(json_obj)) - if re.search(".*already\sexists.*", jobj["error"]["data"], re.I): # already exists + jobj['error']['message'], tmp_data, str(json_obj)) + if re.search(".*already\sexists.*", tmp_data, re.I): # already exists raise Already_Exists(msg, jobj['error']['code']) else: raise ZabbixAPIException(msg, jobj['error']['code'])