From c87fc620e04818ca40434259359996b2a81f981a Mon Sep 17 00:00:00 2001 From: Austin Weisgrau Date: Tue, 21 May 2024 11:28:50 -0700 Subject: [PATCH] Refactor Google Admin using new authed request session --- parsons/google/google_admin.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) 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)