﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
8765	mod_python handler requires explicit str() cast for HttpResponse(mimetype=...)	Ilya Semenov	nobody	"mod_python assumes content_type to be an ASCII string, while django uses unicode strings everywhere.

For example, the following code:
{{{
#!python
att = Attachment.objects.get()
return HttpResponse(content=att.file, mimetype=att.content_type)
}}}

works in django dev server, but crashes in mod_python:

{{{
Traceback (most recent call last):

  File ""/usr/lib/python2.5/site-packages/mod_python/importer.py"", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File ""/usr/lib/python2.5/site-packages/mod_python/importer.py"", line 1229, in _process_target
    result = _execute_target(config, req, object, arg)

  File ""/usr/lib/python2.5/site-packages/mod_python/importer.py"", line 1128, in _execute_target
    result = object(arg)

  File ""/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py"", line 210, in handler
    return ModPythonHandler()(req)

  File ""/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py"", line 193, in __call__
    req.content_type = response['Content-Type']

TypeError: content_type must be a string
}}}

so the only way to make it work is to cast explicitely:
{{{
#!python
return HttpResponse(content=att.file, mimetype=str(att.content_type))
}}}

The str() cast needs to be moved into core/handlers/modpython.py, which already applies it for all headers except Content-Type (since it's handled separately)."		closed	HTTP handling	dev		fixed	mod_python content-type mimetype		Ready for checkin	1	0	0	0	0	0
