Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef6420a

Browse files
authored
Fix "byteswarning" errors in http and model modules (googleapis#860)
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
1 parent c7516a2 commit ef6420a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

googleapiclient/http.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,16 +1760,18 @@ def request(
17601760
connection_type=None,
17611761
):
17621762
resp, content = self._iterable.pop(0)
1763-
if content == "echo_request_headers":
1763+
content = six.ensure_binary(content)
1764+
1765+
if content == b"echo_request_headers":
17641766
content = headers
1765-
elif content == "echo_request_headers_as_json":
1767+
elif content == b"echo_request_headers_as_json":
17661768
content = json.dumps(headers)
1767-
elif content == "echo_request_body":
1769+
elif content == b"echo_request_body":
17681770
if hasattr(body, "read"):
17691771
content = body.read()
17701772
else:
17711773
content = body
1772-
elif content == "echo_request_uri":
1774+
elif content == b"echo_request_uri":
17731775
content = uri
17741776
if isinstance(content, six.text_type):
17751777
content = content.encode("utf-8")

googleapiclient/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def response(self, resp, content):
218218
return self.no_content_response
219219
return self.deserialize(content)
220220
else:
221-
LOGGER.debug("Content from bad request was: %s" % content)
221+
LOGGER.debug("Content from bad request was: %r" % content)
222222
raise HttpError(resp, content)
223223

224224
def serialize(self, body_value):

0 commit comments

Comments
 (0)