Fix parsing of API errors with Unicode err message (#4251)
diff --git a/google/api_core/exceptions.py b/google/api_core/exceptions.py
index eb1d548..75e9b32 100644
--- a/google/api_core/exceptions.py
+++ b/google/api_core/exceptions.py
@@ -378,7 +378,7 @@
error_message = payload.get('error', {}).get('message', 'unknown error')
errors = payload.get('error', {}).get('errors', ())
- message = '{method} {url}: {error}'.format(
+ message = u'{method} {url}: {error}'.format(
method=response.request.method,
url=response.request.url,
error=error_message)
diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py
index df159be..3a77447 100644
--- a/tests/unit/test_exceptions.py
+++ b/tests/unit/test_exceptions.py
@@ -135,6 +135,22 @@
assert exception.message == 'POST https://example.com/: unknown error'
+def test_from_http_response_json_unicode_content():
+ response = make_response(json.dumps({
+ 'error': {
+ 'message': u'\u2019 message',
+ 'errors': ['1', '2']
+ }
+ }).encode('utf-8'))
+
+ exception = exceptions.from_http_response(response)
+
+ assert isinstance(exception, exceptions.NotFound)
+ assert exception.code == http_client.NOT_FOUND
+ assert exception.message == u'POST https://example.com/: \u2019 message'
+ assert exception.errors == ['1', '2']
+
+
def test_from_grpc_status():
message = 'message'
exception = exceptions.from_grpc_status(