From c6912836e88eea45aef7d515383e549082d37717 Mon Sep 17 00:00:00 2001 From: Kapil Thangavelu Date: Wed, 2 Dec 2020 14:52:02 -0500 Subject: [PATCH] fix: handle error on service not enabled (#1117) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1116 🦕 Don't throw invalid JSON messages for valid JSON. --- googleapiclient/http.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/googleapiclient/http.py b/googleapiclient/http.py index 00467747fd3..b8e1b8eaaee 100644 --- a/googleapiclient/http.py +++ b/googleapiclient/http.py @@ -116,7 +116,9 @@ def _should_retry_response(resp_status, content): try: data = json.loads(content.decode("utf-8")) if isinstance(data, dict): - reason = data["error"]["errors"][0]["reason"] + reason = data["error"].get("status") + if reason is None: + reason = data["error"]["errors"][0]["reason"] else: reason = data[0]["error"]["errors"]["reason"] except (UnicodeDecodeError, ValueError, KeyError):