Skip to content

Commit e7ffadc

Browse files
committed
Decoding to string when binary_type is supplied to gcloud.exceptions.make_exception
1 parent 714e84c commit e7ffadc

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

gcloud/datastore/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def test__request_not_200(self):
152152
METHOD = 'METHOD'
153153
DATA = 'DATA'
154154
conn = self._makeOne()
155-
conn._http = Http({'status': '400'}, 'Entity value is indexed.')
155+
conn._http = Http({'status': '400'}, b'Entity value is indexed.')
156156
with self.assertRaises(BadRequest) as e:
157157
conn._request(DATASET_ID, METHOD, DATA)
158158
expected_message = '400 Entity value is indexed.'

gcloud/exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ def make_exception(response, content, use_json=True):
176176
errors = ()
177177

178178
if isinstance(content, six.binary_type):
179+
message = content.decode('utf-8')
179180
if use_json:
180-
payload = json.loads(content.decode('utf-8'))
181+
payload = json.loads(message)
181182
else:
182183
payload = {}
183184
else:

gcloud/test_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _callFUT(self, response, content):
5555
def test_hit_w_content_as_str(self):
5656
from gcloud.exceptions import NotFound
5757
response = _Response(404)
58-
content = '{"message": "Not Found"}'
58+
content = b'{"message": "Not Found"}'
5959
exception = self._callFUT(response, content)
6060
self.assertTrue(isinstance(exception, NotFound))
6161
self.assertEqual(exception.message, 'Not Found')

0 commit comments

Comments
 (0)