MediaMath / t1-python

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

"__init__() takes 2 positional arguments but 3 were given" when downloading report #55

Closed MatiasSMd closed 8 years ago

MatiasSMd commented 8 years ago

I'm getting the following stack trace when trying to download a report:

File "test_program.py", line X, in main_crash
    headers, data = report.get()
  File "my_env/lib/python3.4/site-packages/terminalone/reports.py", line 131, in get
    params=params).iter_lines(decode_unicode=True)
  File "my_env/lib/python3.4/site-packages/terminalone/reports.py", line 87, in _get
    result = XMLParser(response.content)
  File "my_env/lib/python3.4/site-packages/terminalone/xmlparser.py", line 37, in __init__
    self.get_status(result, xml)
  File "my_env/lib/python3.4/site-packages/terminalone/xmlparser.py", line 86, in get_status
    raise exc(status_code, message)
TypeError: __init__() takes 2 positional arguments but 3 were given

Here is the code to reproduce it:

import terminalone

def main_crash():
    t1 = terminalone.T1(Settings.svc_user, Settings.svc_password, Settings.app_key, auth_method="cookie")
    rpts = t1.new("report")

    report = t1.new("report", rpts.report_uri("performance"))
    report.set({
        'dimensions': ['campaign_name'],
        'metrics': ['impressions'],
        'time_aggregation': 'by_day',
        'time_rollup': 'by_day'
    })
    headers, data = report.get()

if __name__ == '__main__':
    main_crash()

Environment:

python --version
Python 3.4.3

pip show TerminalOne
...
Version: 1.0.5
FodT commented 8 years ago

Hi Matias,

the reporting API needs a filter and time window to be specified - see the documentation here https://developer.mediamath.com/docs/read/reports_api/Data_Retrieval, along with the example in t1-python's readme:

report.set({
     'dimensions': ['campaign_id', 'strategy_name'],
     'filter': {'campaign_id': 126173},
     'metrics': ['impressions', 'total_spend'],
     'time_rollup': 'by_day',
     'start_date': '2013-01-01',
     'end_date': '2013-12-31',
     'order': ['date'],
 })

I agree, however, that the error handling around this should be better. I'll keep this ticket open as a placeholder for more graceful error handling

MatiasSMd commented 8 years ago

Thank you @FodT

FWIW further investigation shows that the problem is a ClientError being generated and it requires only one argument (not a status) as being specified in get_status

pswaminathan commented 8 years ago

Fixed by #59 and released in v1.1.2.