From b8486062bf0b463a7dfa480caaca3f606bc869fe Mon Sep 17 00:00:00 2001 From: Chris Staples Date: Thu, 29 Aug 2024 13:13:00 +0100 Subject: [PATCH] Remove KeyError bug --- .../stix2misp/external_stix2_to_misp.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/misp_stix_converter/stix2misp/external_stix2_to_misp.py b/misp_stix_converter/stix2misp/external_stix2_to_misp.py index 997a96d..bc89922 100644 --- a/misp_stix_converter/stix2misp/external_stix2_to_misp.py +++ b/misp_stix_converter/stix2misp/external_stix2_to_misp.py @@ -166,8 +166,9 @@ def _handle_unparsed_content(self): return super()._handle_unparsed_content() unparsed_content = defaultdict(list) for object_id, content in self._observable.items(): - if content['used'][self.misp_event.uuid]: - continue + if self.misp_event.uuid in content['used']: + if content['used'][self.misp_event.uuid]: + continue unparsed_content[content['observable'].type].append(object_id) for observable_type in self._mapping.observable_object_types(): if observable_type not in unparsed_content: @@ -180,8 +181,9 @@ def _handle_unparsed_content(self): continue to_call = f'_parse_{feature}_observable_object' for object_id in unparsed_content[observable_type]: - if self._observable[object_id]['used'][self.misp_event.uuid]: - continue + if self.misp_event.uuid in self._observable[object_id]['used']: + if self._observable[object_id]['used'][self.misp_event.uuid]: + continue try: getattr(self.observable_object_parser, to_call)(object_id) except Exception as exception: