#8765: mod_python handler requires explicit str() cast for
HttpResponse(mimetype=...)
----------------------------------------------+-----------------------------
 Reporter:  semenov                           |       Owner:  nobody    
   Status:  new                               |   Milestone:            
Component:  HTTP handling                     |     Version:  SVN       
 Keywords:  mod_python content-type mimetype  |       Stage:  Unreviewed
Has_patch:  1                                 |  
----------------------------------------------+-----------------------------
 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).

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8765>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to