[mod_python] mod_python re-writing custom HTTP response codes to 500

Graham King graham at gkgk.org
Sat Aug 8 00:09:42 EDT 2009


 It looks like it's mod_python, as I can reproduce it without Django.
Here's what I'm doing

In my apache conf I have:

<Location "/">
    SetHandler mod_python
    PythonHandler test_mp
    PythonDebug on
</Location>

And test_mp.py is:

def handler(req):
    req.content_type = 'text/plain'
    req.status = 278
    req.write('Hello World!\n')
    return 0

The access log has the HTTP status code 278:
127.0.0.1 - - [07/Aug/2009:20:54:36 -0700] "GET / HTTP/1.1" 278 39 "-"
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.13) Gecko/2009080315
Ubuntu/9.04 (jaunty) Firefox/3.0.13"

but a 500 is actually returned:
----
21:06:13 graham at rufus:~$ telnet localhost 80
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.1
Host: localhost

HTTP/1.1 500 Internal Server Error
Date: Sat, 08 Aug 2009 04:06:20 GMT
Server: Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.1 with Suhosin-Patch
mod_python/3.3.1 Python/2.6.2
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/plain

d
Hello World!

0
----

If I change the response code to any official one, 201 for example, it
works fine.

PHP on the same Apache returns the 278, and mod_wsgi seems to work fine as well.

Thanks,
Graham

2009/8/7 Graham Dumpleton <graham.dumpleton at gmail.com>:
> This is better asked on a Django list as unlikely that it would have
> anything to do with mod_python but how you are raising the errors in
> Django and whether Django allows you to override those errors. I would
> suggest that when you post to Django list, that you provide them code
> snippet to show how you are setting up that response status.
>
> Graham
>
> 2009/8/8 Graham King <graham at gkgk.org>:
>>  Hi,
>>
>> When sending an unofficial HTTP response code (I tried 278, 209 and
>> 600) from a Django view, mod_python seems to be re-writing it to 500.
>> Django with mod_wsgi on the same server doesn't change the response
>> code.
>>
>> In mod_python.c (for mod_python 3.3.1) line 1730 there is this comment:
>>  'If the req->status or return code is a weird number that the server
>> doesn't know, it will default to 500 Internal Server Error.'
>>
>> Is this expected behavior? Is there any way around it?
>> I am trying to get a custom HTTP response code to Javascript (XMLHttpRequest).
>>
>> Thanks in advance,
>> Graham King
>> _______________________________________________
>> Mod_python mailing list
>> Mod_python at modpython.org
>> http://mailman.modpython.org/mailman/listinfo/mod_python
>>
>



More information about the Mod_python mailing list