From 3b5d3e2192ce0cdc97854a1d70d5e382e454275c Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 2 Dec 2019 10:57:30 -0800 Subject: [PATCH] fix: in token endpoint request, do not decode the response data if it is not encoded (#393) * fix: in token endpoint request, do not decode the response data if it is not encoded The interface of the underlying transport 'google.auth.transport.Request' that makes the token request does not guarantee the response is encoded. In Python 3, the non-encoded strings do not have 'decode' attribute. Blindly decoding all the response could have the token refresh throw here. --- google/oauth2/_client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/google/oauth2/_client.py b/google/oauth2/_client.py index f92b0970a..4cf7a7fe9 100644 --- a/google/oauth2/_client.py +++ b/google/oauth2/_client.py @@ -103,7 +103,11 @@ def _token_endpoint_request(request, token_uri, body): # occurs. while True: response = request(method="POST", url=token_uri, headers=headers, body=body) - response_body = response.data.decode("utf-8") + response_body = ( + response.data.decode("utf-8") + if hasattr(response.data, "decode") + else response.data + ) response_data = json.loads(response_body) if response.status == http_client.OK: