From 1ae058acde88f736dac4eab5b22a3b77f1d46507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Fri, 19 Jul 2019 14:46:28 +0200 Subject: [PATCH] fix: [add_attribute] Only create a proposal when needed --- pymisp/aping.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pymisp/aping.py b/pymisp/aping.py index a159ebd..861e8a2 100644 --- a/pymisp/aping.py +++ b/pymisp/aping.py @@ -307,6 +307,10 @@ class ExpandedPyMISP(PyMISP): event_id = self.__get_uuid_or_id_from_abstract_misp(event) new_attribute = self._prepare_request('POST', f'attributes/add/{event_id}', data=attribute) if new_attribute.status_code == 403: + if new_attribute['message'] == 'Could not add Attribute': + # In that case, we have a duplicate (uuid or value), and need to return the error to the user + return new_attribute + # At this point, we assume the user tried to add an attribute on an event they don't own # Re-try with a proposal return self.add_attribute_proposal(event_id, attribute, pythonify) new_attribute = self._check_response(new_attribute, expect_json=True)