From 032eaf2d91a1e42a5525c9c1b9c1519c4f192655 Mon Sep 17 00:00:00 2001 From: Matt McDonald Date: Tue, 14 Apr 2020 15:05:08 -0400 Subject: [PATCH] chore: Cleanup "byteswarning" errors in http and model modules This change fixes a few error prone interactions with `str` and `bytes` type objects which surface as exceptions when the googleapiclient library tests are run with the "-bb" command line flag See https://docs.python.org/3/using/cmdline.html#cmdoption-b --- googleapiclient/http.py | 10 ++++++---- googleapiclient/model.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/googleapiclient/http.py b/googleapiclient/http.py index cd2775acc70..41256668b2e 100644 --- a/googleapiclient/http.py +++ b/googleapiclient/http.py @@ -1760,16 +1760,18 @@ def request( connection_type=None, ): resp, content = self._iterable.pop(0) - if content == "echo_request_headers": + content = six.ensure_binary(content) + + if content == b"echo_request_headers": content = headers - elif content == "echo_request_headers_as_json": + elif content == b"echo_request_headers_as_json": content = json.dumps(headers) - elif content == "echo_request_body": + elif content == b"echo_request_body": if hasattr(body, "read"): content = body.read() else: content = body - elif content == "echo_request_uri": + elif content == b"echo_request_uri": content = uri if isinstance(content, six.text_type): content = content.encode("utf-8") diff --git a/googleapiclient/model.py b/googleapiclient/model.py index 554056e3ef2..7255ecf39a7 100644 --- a/googleapiclient/model.py +++ b/googleapiclient/model.py @@ -218,7 +218,7 @@ def response(self, resp, content): return self.no_content_response return self.deserialize(content) else: - LOGGER.debug("Content from bad request was: %s" % content) + LOGGER.debug("Content from bad request was: %r" % content) raise HttpError(resp, content) def serialize(self, body_value):