Opened 4 years ago

Closed 4 years ago

#17154 closed Bug (invalid)

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

Reported by: tdihp@… Owned by: 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 Changed 4 years ago by tdihp@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 4 years ago by poirier

  • Owner changed from nobody to poirier
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 4 years ago by poirier

  • Resolution set to invalid
  • Status changed from new to closed

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