Opened 12 years ago

Closed 12 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

Description

I tried a binary-file-download view based on https://docs.djangoproject.com/en/1.3/ref/request-response/#telling-the-browser-to-treat-the-response-as-a-file-attachment, and I get a error

Django Version: 1.3
Python Version: 2.7.0
Installed Applications:
['django.contrib.contenttypes',
 'pathologist.coldfront.apps',
 'django.contrib.gis']
Installed Middleware:
('django.middleware.gzip.GZipMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware')


Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  178.                 response = middleware_method(request, response)
File "C:\Python27\lib\site-packages\django\middleware\gzip.py" in process_response
  16.         if response.status_code != 200 or len(response.content) < 200:
File "C:\Python27\lib\site-packages\django\http\__init__.py" 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 by tdihp@…, 12 years ago

comment:2 by Dan Poirier, 12 years ago

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

comment:3 by Dan Poirier, 12 years ago

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 https://docs.djangoproject.com/en/1.3/ref/request-response/#id5 :

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