Forum Discussion

VlaMa's avatar
VlaMa
New Member
8 months ago

TypeError: a bytes-like object is required, not 'str'

I used swagger code generator to generate client side interface for my rest API.

When I connect to my server using this swagger client code it gets correct answer but then it fails to parse it.

What I get from server: 
response.data = b'{metadata:{"result_set":{"count":1,"offset":0,"limit":1,"total":1}},results:[{"uuid":"06c60740-05b1-4fad-a0de-1d0931415473","name":"Zumpa"}]}'
--> that's correct response!

and then it fails in some de-serialization with error:
TypeError: a bytes-like object is required, not 'str'

    def __deserialize_model(self, data, klass):
        """Deserializes list or dict to model.
    
        :param data: dict, list.
        :param klass: class literal.
        :return: model object.
        """
    
        if not klass.swagger_types and not self.__hasattr(klass, 'get_real_child_model'):
            return data
    
        kwargs = {}
        if klass.swagger_types is not None:
            for attr, attr_type in six.iteritems(klass.swagger_types):
                if (data is not None and
>                       klass.attribute_map[attr] in data and
                        isinstance(data, (list, dict))):
E                       TypeError: a bytes-like object is required, not 'str'

Any idea what might be wrong or what I do wrong? To me it looks like the problematic is "b" at the beginning of response data as it might say some binary data will follow but there is a string instead. 

I use swagger v3, the latest version from gitlab repo.

No RepliesBe the first to reply