STIXProject / python-stix

A Python library for parsing, manipulating, and generating STIX content.
http://stix.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
241 stars 88 forks source link

Facing this issue while try to append EmailMessage to EmailRecipient. #346

Closed NikhilAjmera closed 6 years ago

NikhilAjmera commented 6 years ago

`

In [22]: email_recipients = EmailRecipients()

In [23]: email_address.to_xml()
Out[23]: b'<AddressObj:AddressObjectType xmlns:xlink="http://www.w3.org/1999/xlink"\n\txmlns:xs="http://www.w3.org/2001/XMLSchema"\n\txmlns:ds="http://www.w3.org/2000/09/xmldsig#"\n\txmlns:cyboxCommon="http://cybox.mitre.org/common-2"\n\txmlns:AddressObj="http://cybox.mitre.org/objects#AddressObject-2"\n\txmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n\txmlns:example="http://example.com"\n\t\n\txsi:schemaLocation="http://cybox.mitre.org/common-2 http://cybox.mitre.org/XMLSchema/common/2.1/cybox_common.xsd\n\thttp://cybox.mitre.org/objects#AddressObject-2 http://cybox.mitre.org/XMLSchema/objects/Address/2.1/Address_Object.xsd" xsi:type="AddressObj:AddressObjectType" category="ipv4-net" is_source="false" is_destination="true" is_spoofed="false">\n    <AddressObj:Address_Value>h1@example.com</AddressObj:Address_Value>\n    <AddressObj:VLAN_Name>iph1</AddressObj:VLAN_Name>\n    <AddressObj:VLAN_Num>198</AddressObj:VLAN_Num>\n</AddressObj:AddressObjectType>\n'

In [24]: email_recipients.append(email_address)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/mixbox/typedlist.py in _fix_value(self, value)
     60         try:
---> 61             return self._castfunc(value)
     62         except:

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/cybox/objects/address_object.py in __init__(self, addr_string)
     63     def __init__(self, addr_string=None):
---> 64         super(EmailAddress, self).__init__(addr_string, Address.CAT_EMAIL)
     65 

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/cybox/objects/address_object.py in __init__(self, address_value, category)
     41         super(Address, self).__init__()
---> 42         self.address_value = address_value
     43         self.category = category

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/mixbox/fields.py in __set__(self, instance, value)
    209         else:
--> 210             value = self._clean(value)
    211 

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/mixbox/fields.py in _clean(self, value)
    185         elif self.is_type_castable:  # noqa
--> 186             return self.type_(value)
    187 

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/cybox/common/properties.py in __init__(self, value)
     89 
---> 90         self.value = value
     91         self.datatype = self.default_datatype

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/mixbox/fields.py in __set__(self, instance, value)
    212         if self.preset_hook:
--> 213             self.preset_hook(instance, value)
    214 

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/cybox/common/properties.py in validate_string_type(instance, value)
     26     else:
---> 27         raise ValueError("Value must be a string. Received %r" % value)
     28 

ValueError: Value must be a string. Received <cybox.objects.address_object.EmailAddress object at 0x7fca17fa5f60>

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-24-6e565080a5e9> in <module>()
----> 1 email_recipients.append(email_address)

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/_collections_abc.py in append(self, value)
    897     def append(self, value):
    898         'S.append(value) -- append value to the end of the sequence'
--> 899         self.insert(len(self), value)
    900 
    901     def clear(self):

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/mixbox/entities.py in insert(self, idx, value)
    569         if not value:
    570             return
--> 571         self._inner.insert(idx, value)
    572 
    573     @classmethod

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/mixbox/typedlist.py in insert(self, idx, value)
    105             self._inner.insert(idx, value)
    106         elif self._is_type_castable():
--> 107             value = self._fix_value(value)
    108             self._inner.insert(idx, value)
    109         else:

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/mixbox/typedlist.py in _fix_value(self, value)
     68                 self._type              # Expected type of input value
     69             )
---> 70             six.reraise(TypeError, TypeError(error), sys.exc_info()[-1])
     71 
     72     def _is_type_castable(self):

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/mixbox/vendor/six.py in reraise(tp, value, tb)
    690                 value = tp()
    691             if value.__traceback__ is not tb:
--> 692                 raise value.with_traceback(tb)
    693             raise value
    694         finally:

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/mixbox/typedlist.py in _fix_value(self, value)
     59         """
     60         try:
---> 61             return self._castfunc(value)
     62         except:
     63             error = "Can't put '{0}' ({1}) into a {2}. Expected a {3} object."

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/cybox/objects/address_object.py in __init__(self, addr_string)
     62 
     63     def __init__(self, addr_string=None):
---> 64         super(EmailAddress, self).__init__(addr_string, Address.CAT_EMAIL)
     65 
     66     @classmethod

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/cybox/objects/address_object.py in __init__(self, address_value, category)
     40     def __init__(self, address_value=None, category=None):
     41         super(Address, self).__init__()
---> 42         self.address_value = address_value
     43         self.category = category
     44 

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/mixbox/fields.py in __set__(self, instance, value)
    208                 value = self._listfunc(self._clean(x) for x in value if x is not None)
    209         else:
--> 210             value = self._clean(value)
    211 
    212         if self.preset_hook:

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/mixbox/fields.py in _clean(self, value)
    184             return value
    185         elif self.is_type_castable:  # noqa
--> 186             return self.type_(value)
    187 
    188         error_fmt = "%s must be a %s, not a %s"

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/cybox/common/properties.py in __init__(self, value)
     88         self._force_datatype = False
     89 
---> 90         self.value = value
     91         self.datatype = self.default_datatype
     92 

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/mixbox/fields.py in __set__(self, instance, value)
    211 
    212         if self.preset_hook:
--> 213             self.preset_hook(instance, value)
    214 
    215         instance._fields[self] = value

~/Cyware/source-code/CTIX-S/venv/lib/python3.5/site-packages/cybox/common/properties.py in validate_string_type(instance, value)
     25             validate_string_type(instance, x)
     26     else:
---> 27         raise ValueError("Value must be a string. Received %r" % value)
     28 
     29 

TypeError: Can't put 'h1@example.com' (<class 'cybox.objects.address_object.EmailAddress'>) into a <class 'mixbox.typedlist.TypedList'>. Expected a <class 'cybox.objects.address_object.EmailAddress'> object.

` Can you please tell me where is issue.

emmanvg commented 6 years ago

I can't really observe the problem without more information. I was unable to reproduce your behavior writing this small script:

from cybox.objects.email_message_object import *

email_address = EmailAddress("h1@example.com")
email_address.vlan_name = "iph1"
email_address.vlan_num = 198
email_address.is_destination = True
email_address.is_source = False
email_address.is_spoofed = False
email_recipients = EmailRecipients()
email_address.to_xml()
email_recipients.append(email_address)
email_recipients.to_xml()
emmanvg commented 6 years ago

@NikhilAjmera did you manage to fix the issue?

NikhilAjmera commented 6 years ago

@emmanvg Yah I am able to fix this issue. Thanks for your help.

emmanvg commented 6 years ago

Awesome, I will be closing this issue since it is not a problem in the library. Thanks for the submission!