From 1b552bc0ccbc41bf3394fd1b97e8568ee91b7d9f Mon Sep 17 00:00:00 2001 From: Joel Wilsson Date: Wed, 24 Jan 2018 13:51:38 +0100 Subject: [PATCH] Copy of changes from fix-mirror-bugs branch --- cognite/_utils.py | 22 ++++++++++++++++++---- cognite/timeseries.py | 9 ++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/cognite/_utils.py b/cognite/_utils.py index 64a5b007b2..0e1656510e 100644 --- a/cognite/_utils.py +++ b/cognite/_utils.py @@ -16,18 +16,32 @@ def get_request(url, params=None, headers=None): '''Perform a GET request with a predetermined number of retries.''' for _ in range(_constants.RETRY_LIMIT + 1): - res = requests.get(url, params=params, headers=headers) + try: + res = requests.get(url, params=params, headers=headers) + except Exception as e: + raise _APIError(e) if res.status_code == 200: return res - raise _APIError(res.json()['error']) + try: + err_mess = res.json()['error'] + except: + err_mess = res.content + raise _APIError(err_mess) def post_request(url, body, headers=None): '''Perform a POST request with a predetermined number of retries.''' for _ in range(_constants.RETRY_LIMIT + 1): - res = requests.post(url, data=json.dumps(body), headers=headers) + try: + res = requests.post(url, data=json.dumps(body), headers=headers) + except Exception as e: + raise _APIError(e) if res.status_code == 200: return res - raise _APIError(res.json()['error']) + try: + err_mess = res.json()['error'] + except: + err_mess = res.content + raise _APIError(err_mess) def granularity_to_ms(time_string): '''Returns millisecond representation of granularity time string''' diff --git a/cognite/timeseries.py b/cognite/timeseries.py index 9d613dac6d..ecf28806c2 100644 --- a/cognite/timeseries.py +++ b/cognite/timeseries.py @@ -189,7 +189,14 @@ def get_datapoints_frame(tag_ids, aggregates, granularity, start=None, end=None, ''' api_key, project = config.get_config_variables(api_key, project) url = config.get_base_url() + '/projects/{}/timeseries/dataframe'.format(project) - per_tag_limit = int(_constants.LIMIT / len(tag_ids)) + num_aggregates = 0 + num_agg_per_tag = len(aggregates) + for tag_id in tag_ids: + if isinstance(tag_id, str): + num_aggregates += num_agg_per_tag + else: + num_aggregates += len(tag_id['aggregates']) + per_tag_limit = int(_constants.LIMIT / num_aggregates) body = { 'items': [{'tagId': '{}'.format(tag_id)} if isinstance(tag_id, str)