MediaMath / t1-python

Python SDK for MediaMath Platform APIs
https://developer.mediamath.com/
Apache License 2.0
18 stars 30 forks source link

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

Closed zachliu closed 8 years ago

zachliu commented 8 years ago

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'})
pswaminathan commented 8 years ago

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.

zachliu commented 8 years ago

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