          charset = renderer.charset
          content_type = self.content_type
  
          if content_type is None and charset is not None:
              content_type = "{0}; charset={1}".format(media_type, charset)
          elif content_type is None:
              content_type = media_type
          self['Content-Type'] = content_type
  
          ret = renderer.render(self.data, accepted_media_type, context)
 
</s> remove         if isinstance(ret, six.text_type):
 </s> add         if isinstance(ret, str): </s> remove             content_type = "{0}; charset={1}".format(
 </s> add             content_type = "{}; charset={}".format( </s> remove         return super(APIRequestFactory, self).generic(
 </s> add         return super().generic( </s> remove             for name, value in six.iteritems(headers):
 </s> add             for name, value in headers.items(): </s> remove             if isinstance(ret, six.text_type):
 </s> add             if isinstance(ret, str):
            content_type = "{}; charset={}".format(media_type, charset)
          charset = renderer.charset
          content_type = self.content_type
  
          if content_type is None and charset is not None:
            content_type = "{}; charset={}".format(media_type, charset)
          elif content_type is None:
              content_type = media_type
          self['Content-Type'] = content_type
  
          ret = renderer.render(self.data, accepted_media_type, context)
keep keep keep keep replace keep keep keep keep keep
 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/response.py