diff --git a/parsons/google/google_admin.py b/parsons/google/google_admin.py index e273353610..b69cd5b3d9 100644 --- a/parsons/google/google_admin.py +++ b/parsons/google/google_admin.py @@ -1,4 +1,3 @@ -import json import uuid from google.auth.transport.requests import AuthorizedSession @@ -51,7 +50,9 @@ def _paginate_request(self, endpoint, collection, params=None): # Return type from Google Admin is a tuple of length 2. Extract desired result from 2nd item # in tuple and convert to json - res = json.loads(self.client.request(req_url + param_str, "GET")[1].decode("utf-8")) + res = self.client.request("GET", req_url + param_str).json() + if "error" in res: + raise RuntimeError(res["error"].get("message")) # Paginate ret = [] @@ -63,12 +64,10 @@ def _paginate_request(self, endpoint, collection, params=None): param_arr.append("pageToken=" + res["nextPageToken"]) else: param_arr[-1] = "pageToken=" + res["nextPageToken"] - res = json.loads( - self.client.request(req_url + "?" + "&".join(param_arr), "GET")[1].decode( - "utf-8" - ) - ) - ret += res[collection] + response = self.client.request("GET", req_url + "?" + "&".join(param_arr)).json() + if "error" in response: + raise RuntimeError(response["error"].get("message")) + ret += response[collection] return Table(ret)