MediaMath / t1-python

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

Version Errors #36

Closed anoonan closed 9 years ago

anoonan commented 9 years ago

I'm getting version errors when trying to bulk update technology targeting. Here is an example of the error I am getting:

Traceback (most recent call last):
  File "technology_remove.py", line 42, in <module>
    tech_excluded.save()
  File "/usr/local/lib/python2.7/site-packages/terminalone/models/targetdimension.py", line 57, in save
    return super(TargetDimension, self).save(data=data)
  File "/usr/local/lib/python2.7/site-packages/terminalone/entity.py", line 217, in save
    data = self._validate_write(data)
  File "/usr/local/lib/python2.7/site-packages/terminalone/entity.py", line 171, in _validate_write
    data['version'] = self.version
  File "/usr/local/lib/python2.7/site-packages/terminalone/entity.py", line 78, in __getattr__
    raise AttributeError(attribute)
AttributeError: version

Here is the basic script I am using, the "tech_excluded.save()" at the end is what is causing the errors.

for campaign_id in CAMPAIGNS:
    strategies = t1.get('strategies', limit={'campaign':campaign_id}, get_all=True, full='strategy')

    for strategy in strategies:
        #get technology excluded object
        tech_excluded = t1.get('strategies', strategy.id, child='browser', full='*')

        #get list of id's of excluded browsers
        exclude = [obj.id for obj in tech_excluded.properties['exclude']]

        if strategy.status == True:
            for browser_to_remove in TECH_TO_REMOVE:
                if browser_to_remove in exclude:
                    exclude.remove(browser_to_remove)
                else:
                    print "Strategy", strategy.id, "is not excluding that browser."

        tech_excluded.properties['exclude'] = exclude
        tech_excluded.save()

Let me know if you need anything else. Thanks!