Opened 7 years ago

Closed 7 years ago

#17154 closed Bug (invalid)

http.__init__._get_content raises TypeError if _content is not string

Reported by: tdihp@… Owned by: Dan Poirier
Component: HTTP handling Version: 1.3
Severity: Normal Keywords: response.content
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I tried a binary-file-download view based on, and I get a error

Django Version: 1.3
Python Version: 2.7.0
Installed Applications:
Installed Middleware:

File "C:\Python27\lib\site-packages\django\core\handlers\" in get_response
  178.                 response = middleware_method(request, response)
File "C:\Python27\lib\site-packages\django\middleware\" in process_response
  16.         if response.status_code != 200 or len(response.content) < 200:
File "C:\Python27\lib\site-packages\django\http\" in _get_content
  596.         return smart_str(''.join(self._container), self._charset)

Exception Type: TypeError at /api/gis/1.0/image/6103200d/
Exception Value: sequence item 0: expected string, buffer found

it seems when content is no string, anything touches response.content breaks

maybe fix this use self._is_string will do?

Change History (3)

comment:1 Changed 7 years ago by tdihp@…

comment:2 Changed 7 years ago by Dan Poirier

Owner: changed from nobody to Dan Poirier
Triage Stage: UnreviewedAccepted

comment:3 Changed 7 years ago by Dan Poirier

Resolution: invalid
Status: newclosed

It looks as if the content has been set to an iterator whose first item was a buffer.

From the doc on HttpResponse at :

content can be an iterator or a string. If it's an iterator, it should return strings, and those strings will be joined together to form the content of the response.

Note: See TracTickets for help on using tickets.
Back to Top