[mod_python] Returning a Apache return code

Jorey Bump list at joreybump.com
Tue Nov 30 12:12:32 EST 2004


Golawala, Moiz M (GE Infrastructure) wrote:

> I have am newbie and I seems to be having a problem return a
> different apache return code. In my httpd.conf file I am using
> PythonHandler mod_python.publisher.
> 
> In my index.py file.
> 
> index(req): req.header_out['Location'] = "http://someurl:8080/ 
 > return apache.HTTP_PERMANENTLY_MOVED

Try this:

from mod_python import apache

index(req)
     status = apache.HTTP_MOVED_PERMANENTLY
     req.headers_out['Location'] = url
     req.status = status
     raise apache.SERVER_RETURN, status

More info:

  http://www.modpython.org/live/current/doc-html/pyapi-handler.html

> my problem is that this returns:
> 
> HTTP/1.1 200 OK Date: Tue, 30 Nov 2004 01:12:06 GMT Server:
> Apache/2.0.49 (Fedora) Location:  "http://someurl:8080/" Connection:
> close Transfer-Encoding: chunked Content-Type: text/html;
> charset=UTF-8
> 
> 3 301 0
> 
> 
> I would like to return HTTP/1.1 301.. instead of HTTP/1.1 200 OK.
> 
> For some reason anything that the method return the publisher handler
> puts it in the body of the request I cannot return a different return
> code other than the default apache.OK
> 
> Could some one please help me with this.


More information about the Mod_python mailing list