[mod_python] ImportError: No module named _apache

Graham Dumpleton grahamd at dscpl.com.au
Mon Nov 22 19:04:32 EST 2004


On Nov 22 18:24, Alan Ezust <alan.ezust at gmail.com> wrote:
>
> Subject: Re: [mod_python] ImportError: No module named _apache
>
> Thanks for the reply. I got rid of the execCGI permissions in that
> directory (I added it before because apache server was complaining
> about how the permissions were not correct).
> 
> Now I point my browser to the modtest.py (a helloworld application),
> and it asks me to open the URL with an external application, and
> attempts to open it as text. When I do that, I can see that the script
> has executed and the output is in the text file, but why is it not
> opening in my browser?
> 
>  Is there MIME-type preamble I must spit out first?

Try this handler example:

def handler(req):
  req.content_type = "text/plain"
  req.send_http_header()
  req.write("Hello World!")
  return apache.OK

Thus setting "req.content_type" is how you set the mime type.

If you don't set it, Apache will return whatever it may have set as
its default mime type, or perhaps nothing at all depending on your
configuration. If it is sends back nothing at all, you will be at the
mercy of your browsers interpretation of any extension on the
URL you used.

Ensure that you have "req.send_http_header()" if you are using
mod_python 2.X. From memory, in mod_python 3.X it will emit
the headers automatically even if you don't make that call, but
in 2.X it will not.

--
Graham Dumpleton (grahamd at dscpl.com.au)


More information about the Mod_python mailing list