              except Exception:
                  pass
          elif hasattr(obj, '__iter__'):
              return tuple(item for item in obj)
          return super(JSONEncoder, self).default(obj)
 
</s> remove     elif isinstance(val, six.string_types):
 </s> add     elif isinstance(val, str): </s> remove             return six.text_type(obj)
 </s> add             return str(obj) </s> remove     return six.text_type(value)
 </s> add     return str(value) </s> remove         name = six.text_type(value.obj)
 </s> add         name = str(value.obj) </s> remove         return super(RelatedField, self).get_attribute(instance)
 </s> add         return super().get_attribute(instance)
        return super().default(obj)
              except Exception:
                  pass
          elif hasattr(obj, '__iter__'):
              return tuple(item for item in obj)
        return super().default(obj)
keep keep keep keep replace
 Dropped Python 2 compatibility. (#6615)

Thanks to Jon Dufresne (@jdufresne) for review.

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Rizwan Mansuri <Rizwan@webbyfox.com> 
rest_framework/utils/encoders.py