From 7f512de5641acaafa6fd9f234649185a2a3e30a6 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Mon, 17 Jul 2017 22:04:21 -0700 Subject: [PATCH] Making sure we pass unicode to `json.loads()` rather than `bytes`. Fixes #12. --- google/resumable_media/_upload.py | 3 ++- tests/unit/test__upload.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/google/resumable_media/_upload.py b/google/resumable_media/_upload.py index 7637fdfb..7853168a 100644 --- a/google/resumable_media/_upload.py +++ b/google/resumable_media/_upload.py @@ -571,7 +571,8 @@ def _process_response(self, response): response, (http_client.OK, resumable_media.PERMANENT_REDIRECT), self._get_status_code, callback=self._make_invalid) if status_code == http_client.OK: - json_response = json.loads(self._get_body(response)) + body = self._get_body(response) + json_response = json.loads(body.decode('utf-8')) self._bytes_uploaded = int(json_response[u'size']) # Tombstone the current upload so it cannot be used again. self._finished = True diff --git a/tests/unit/test__upload.py b/tests/unit/test__upload.py index f1434dd4..000d593d 100644 --- a/tests/unit/test__upload.py +++ b/tests/unit/test__upload.py @@ -574,6 +574,7 @@ def test__process_response_success(self): total_bytes = 158 response_body = u'{{"size": "{:d}"}}'.format(total_bytes) + response_body = response_body.encode('utf-8') # Check status before. assert upload._bytes_uploaded == 0 assert not upload._finished