From 0f7fa5287e2b615b61920deaa7d4cbb919a02ff9 Mon Sep 17 00:00:00 2001 From: Artur Maciag Date: Fri, 24 Jan 2020 15:37:23 +0000 Subject: [PATCH] Python 3.5 json binary input deserialization fix --- openapi_core/schema/media_types/models.py | 5 ++--- openapi_core/schema/media_types/util.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 openapi_core/schema/media_types/util.py diff --git a/openapi_core/schema/media_types/models.py b/openapi_core/schema/media_types/models.py index ba31ef1..69cceba 100644 --- a/openapi_core/schema/media_types/models.py +++ b/openapi_core/schema/media_types/models.py @@ -1,9 +1,8 @@ """OpenAPI core media types models module""" from collections import defaultdict -from json import loads - from openapi_core.schema.media_types.exceptions import InvalidMediaTypeValue +from openapi_core.schema.media_types.util import json_loads from openapi_core.schema.schemas.exceptions import ( CastError, ValidateError, ) @@ -11,7 +10,7 @@ from openapi_core.unmarshalling.schemas.exceptions import UnmarshalError MEDIA_TYPE_DESERIALIZERS = { - 'application/json': loads, + 'application/json': json_loads, } diff --git a/openapi_core/schema/media_types/util.py b/openapi_core/schema/media_types/util.py new file mode 100644 index 0000000..e09c1d1 --- /dev/null +++ b/openapi_core/schema/media_types/util.py @@ -0,0 +1,10 @@ +from json import loads + +from six import binary_type + + +def json_loads(value): + # python 3.5 doesn't support binary input fix + if isinstance(value, (binary_type, )): + value = value.decode() + return loads(value)