Skip to content

Commit c691283

Browse files
authored
fix: handle error on service not enabled (#1117)
Fixes #1116 🦕 Don't throw invalid JSON messages for valid JSON.
1 parent 334b6e6 commit c691283

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

googleapiclient/http.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ def _should_retry_response(resp_status, content):
116116
try:
117117
data = json.loads(content.decode("utf-8"))
118118
if isinstance(data, dict):
119-
reason = data["error"]["errors"][0]["reason"]
119+
reason = data["error"].get("status")
120+
if reason is None:
121+
reason = data["error"]["errors"][0]["reason"]
120122
else:
121123
reason = data[0]["error"]["errors"]["reason"]
122124
except (UnicodeDecodeError, ValueError, KeyError):

0 commit comments

Comments
 (0)