Mod_python produces no output

Just installed and configured mod_python 3.2.8 on a CentOS 5 (Apache 2.2.3) server with Python 2.4.3. It is loaded fine by Apache.

I activated the mpinfo test page and it works. So I wrote a simple "Hello World" with the following code:

from mod_python import apache def handler(req): req.content_type = 'text/plain' req.write("Hello World!") req.flush() return apache.OK

It outputs a blank page, with no text and no source. If I consciously create a syntax error I get the error output on the URL, for example (when I put a space before "def"):

Mod_python error: "PythonHandler mod_python.cgihandler" Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/mod_python/", line 299, in HandlerDispatch result = object(req) File "/usr/lib/python2.4/site-packages/mod_python/", line 96, in handler imp.load_module(module_name, fd, path, desc) File "/var/www/vhosts/localhost/httpdocs/", line 3 def handler(req): ^ SyntaxError: invalid syntax

I have spent about five hours browsing different tutorials, faqs and trouble shooting guides but can't find a description of this exakt issue.

What do you think could be the issue/cause?

EDIT: Here is the Apache configuration for the site...

<Directory /> Options FollowSymLinks AllowOverride None AddHandler mod_python .py PythonHandler mptest PythonDebug On </Directory>

EDIT 2: Ah, another thing I forgot to mention is that I intend to use mod_python to write Apache extensions. The application itself is written in PHP but I need to make some security tweeks on the server :)

-------------Problems Reply------------

Don't use mod_python.

A common mistake is to take mod_python as "mod_php, but for python" and that is not true. mod_python is more suited to writing apache extensions, not web applications.

The standartized protocol to use between python web applications and web servers (not only apache) is WSGI. Using it ensures that you can publish your application to any wsgi-compliant webserver (almost all modern web servers are wsgi-compliant)

On apache, use mod_wsgi instead.

Your example rewritten using the wsgi standard and mod_wsgi on apache:

def application(environ, start_response):
start_response('200 OK', [('content-type', 'text/plain')])
return ['Hello World']

Apache configuration:

WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/
<Directory /usr/local/www/wsgi-scripts>
Order allow,deny
Allow from all

Now just go to http://localhost/myapp and the script will run. Additionally, any access under this root (i.e. http://localhost/myapp/stuff/here) will be handled by this script.

It's a good idea to choose a web framework. CherryPy. Pylons. Django. They make things even easier.

A good website to look at is

Your original problem is that mod_python.cgihandler is being called to handle the request. This means your Python script file is being interpreted as a CGI script. Thus, no wonder it doesn't return anything.

You likely have conflicting definition in your Apache configuration which is enabling the mod_python.cgihandler.

I make a complete new answer for clarity...

I decided to install mod_wsgi instead. So I've set it up and when I go to my testfile I just see the page source. I haven't been spending any time on finding the issue yet, so I'll get back to you when I either solve the problem or decide that I need more help :)

Thank you :)

Category:python Views:0 Time:2009-10-02

Related post

  • Java equivalent to JavaScript's encodeURIComponent that produces identical output? 2009-03-03

    I've been experimenting with various bits of Java code trying to come up with something that will encode a string containing quotes, spaces and "exotic" Unicode characters and produce output that's identical to JavaScript's encodeURIComponent functio

  • Crystal report viewer Print and Preview then Print produce different output 2009-09-18

    I use Crystal Report Basic to create report for my application, my problem is when I view my report in report viewer and click print (without preview) it produce different output (page margin is different) as I preview and print the same report. I wa

  • How to specify if a T4 file should produce any output 2010-02-14

    I am using T4 for generation of some DTO classes + mappers. I am splitting the files in a number of re-usable bits (some of which containing common methods, some others common procedures) and including them into the T4 templates that will produce my

  • Running a command that produces no output with SharpSSH 2010-05-07

    I want to run a command using ssh. I am using the SharpSSH library, as in this example: using System; using Tamir.SharpSsh; class Program { static void Main(string[] args) { string hostName = ""; string userName = "user"; string privateKe

  • PHP - Calling .php file from command line produces no output 2010-07-12

    I have a simple cmd.php page to run commands I enter using shell_exec () and show the output. PHP is running as CGI Entering "php -v" and most commands just show "Content-type: text/html" and then the current page's HTML source. However, calling PHP

  • Can UB cause several single-threaded app runs to produce different outputs? 2010-08-22

    Is it possible for code that meets the following conditions to produce different outputs for each run for the same input? The code is single threaded, though it does link against a thread-safe runtime library. There are no explicit calls to rand() or

  • Producing LaTeX output in Java 2010-11-19

    Is there a Java library for producing LaTeX output from Java? --------------Solutions------------- To render Latex: JLatexMath: To produce Latex: JTex: It looks like SCaVis

  • console.dir(this) not producing any output 2010-12-27

    I have this: <body> <script> console.log(this); console.dir(this); console.dirxml(this); </script> </body> Why does console.dir(this) not produce any output? --------------Solutions------------- It should show the console obje

  • cygwin g++ produces no output 2011-01-03

    I just installed g++ from cygwin, when I try to compile a C++ file I am not getting any executable produced by the compiler, see example below. What's going wrong? Directory of C:\helloworld 01/02/2011 04:50 PM . 01/02/2011 04:50 PM .. 01/02/2011 04:

  • My xslt not produce correct output? 2011-01-04

    My XML is 'input.xsl' <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="input.xsl"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <countr

  • Counter in a recursive function in Python is not producing an output with Print(using Netbeans) 2011-07-17

    I am new to Python. I am using Netbeans IDE 6.8. When I run the code below- using RUN FILE- it does not seem to produce any output. On the other hand when I debug the code, the output shows the value of counter- 6. Is this a problem with the program

  • wsdl2java doesn't produce any output 2011-09-09

    I'm fairly new to web services and I've successfully created a web service using axis2 and tomcat 7. Now I'm trying to create a client for the web service using wsdl2java. I'm working on Windows so the command I've been trying is this: C:\axis2-1.5.4

  • Trace.WriteLine not producing any output 2011-12-13

    I'm having an odd problem With Trace.WriteLine not producing any output. I've traced the code and Trace.Writeline is definitely getting called, but no output is appearing in the Output window or in SysInternals' DebugView. Is something wrong with my

  • Project Euler 43: my attempt produces no output 2012-03-22

    I'm currently in the process of solving euler problems to improve in Haskell. Though, my attempt at solving problem n° 43 produces no output. Just to be clear, I'm not asking for help on the "problem algorithmic" part, even if I'm wrong. I'm specific

  • Why isn't Stanford Topic Modeling Toolbox producing lda-output directory? 2012-04-18

    I tried to run this code from github (following the 1-2-3 steps) which identifies 30 topics in Sarah Palin's 14,500 emails. The topics discovered by the author are here. However, Stanford Topic Modeling Toolbox is not producing lda-output directory f

  • Python 3.2 _thread module produces no output using Ubuntu 12.04, but works fine with windows 7 2012-08-20

    I'm hoping that someone has a quick and easy solution to this issue that I'm facing. I'm working through chapter 5 of the 4th edition of the Programming Python book by Mark Lutz and I'm having some troubles beginning on page 189. Basically, there is

  • php mysql output array with json_encode to javascript produce no output 2015-01-11

    mysql produced an array and use json_encode to generated the output. Javascript produce no output. There are two rows in the query results: 科目編號 科目 課程簡介 課程期間 課員 208.01.00 舊約綜覽上 2015 class of 舊約綜覽上 2015-06 to 2015-08 劉健全 102.00.00 成長班 2015 class of 成長

  • PartCover console produces empty output xml 2009-03-31

    I'm using partcover to produce codecoverage for a bunch of mstest powered unit tests. I use the command line: PartCover.exe --target "c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe" --target-args "/testcontainer:c:\CrusieControlP

  • XslTransform.Transform to produce multiple output files 2009-07-17

    I need to produce multiple HTML report files from an XML data file and I'm using C# (.NET 3.5). I essentially need on HTML report for each of certain child trees in the XML file (but they have to include some parent info). I've decided to use XSLT, b

Copyright (C), All Rights Reserved.

processed in 0.194 (s). 11 q(s)