                  raise ValueError("JSON can't represent timezone-aware times.")
              representation = obj.isoformat()
              return representation
          elif isinstance(obj, datetime.timedelta):
              return six.text_type(total_seconds(obj))
          elif isinstance(obj, decimal.Decimal):
              # Serializers will coerce decimals to strings by default.
              return float(obj)
          elif isinstance(obj, uuid.UUID):
              return six.text_type(obj)
 
</s> remove     def test_total_seconds(self):
        class MockTimedelta(object):
            days = 1
            seconds = 1
            microseconds = 100
        timedelta = MockTimedelta()
        expected = (timedelta.days * 86400.0) + float(timedelta.seconds) + (timedelta.microseconds / 1000000.0)
        assert compat.total_seconds(timedelta) == expected

 </s> add  </s> remove from rest_framework.compat import coreapi, total_seconds
 </s> add from rest_framework.compat import coreapi </s> remove def total_seconds(timedelta):
    # TimeDelta.total_seconds() is only available in Python 2.7
    if hasattr(timedelta, 'total_seconds'):
        return timedelta.total_seconds()
    else:
        return (timedelta.days * 86400.0) + float(timedelta.seconds) + (timedelta.microseconds / 1000000.0)


 </s> add 
            return six.text_type(obj.total_seconds())
                  raise ValueError("JSON can't represent timezone-aware times.")
              representation = obj.isoformat()
              return representation
          elif isinstance(obj, datetime.timedelta):
            return six.text_type(obj.total_seconds())
          elif isinstance(obj, decimal.Decimal):
              # Serializers will coerce decimals to strings by default.
              return float(obj)
          elif isinstance(obj, uuid.UUID):
              return six.text_type(obj)
keep keep keep keep replace keep keep keep keep keep
 Drop compat wrapper for TimeDelta.total_seconds() (#5577)

TimeDelta.total_seconds() was introduced in Python 2.7 and 3.2. It is
available on all supported Python versions.

https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
https://docs.python.org/3/library/datetime.html#datetime.timedelta.total_seconds 
rest_framework/utils/encoders.py