MediaMath/t1-python

XMLParser fails because of missing '<entity></entity>' in XML response

Closed this issue · 2 comments

For example, the xml response of this endpoint has no ""

POST $API_BASE/site_lists/$SITE_LIST_ID/domains

Hence, the following code works but return an error (AttributeError: 'XMLParser' object has no attribute 'entities')

from terminalone import T1
t1 = T1(USERNAME, PASSWORD, APIKEY, 'cookie')
t1._post('api/v2.0', rest='site_lists/10000/domains', data={'domains': 'abc.com'})

Hi @zachliu , great question. I should first say that given that the post function is prefixed by an underscore, we can't guarantee its safe usage from update to update. Having said that, we have run into this with other similar situations. For instance, in strategy.py1:

    def save_domains(self, data):
        url = self._construct_url(addl=['domain_restrictions', ])
        # this endpoint doesn't return an entity like the supplies endpoint
        # so we ignore the error
        with suppress(AttributeError):
            entity, _ = super(Strategy, self)._post(PATHS['mgmt'], url, data)

We can add a similar method into the site list entity (or if you would like to submit it as a PR, we are happy to accept!); if you're in need of a workaround prior to that support, you can suppress the AttributeError similarly.

1suppress here is in the standard library's contextlib in Python 3.4, but if you're using Python 2, you can see our implementation in suppressed.py.

Hi @pswaminathan , thank you for the reply. I think I'm going to suppress the error for now.