Skip to content

Commit

Permalink
Making sure we pass unicode to json.loads() rather than bytes.
Browse files Browse the repository at this point in the history
Fixes #12.
  • Loading branch information
dhermes committed Jul 18, 2017
1 parent 3625888 commit 7f512de
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion google/resumable_media/_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test__upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7f512de

Please sign in to comment.