LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (https://www.linuxquestions.org/questions/debian-26/)
-   -   [Debian] Mod-python not working (https://www.linuxquestions.org/questions/debian-26/%5Bdebian%5D-mod-python-not-working-337735/)

freek sanders 06-27-2005 02:38 PM

[Debian] Mod-python not working
 
I can not get mod-python to work on my server. Everytime I load a page which is supposed to execute python code, my browser offers to save the file (*.py)

Example .py file I tried:

# /var/www/html/helloworld.py
from mod_python import apache

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

PS: Mod-python was installed using Aptitude.

I run Apache 1.3 together with mod-php and phpmyadmin, all of which work (finally ;))

Can anybody please help me? Which files did I forget to edit, etc?

codec 06-28-2005 05:50 PM

hey! What are you doing with modpython?

I use ubuntu, apache 1.3 and mod_python 2.7 for some intranet application

By the way, please tell me if you know how to accept arguments in common python handler. (I know how to do it in mp2 publisher or mp3 both handlers)

active modpython in apache:
dpkg-reconfigure apache

Code:

=== httpd.conf ===
<Directory /var/www/>
    Options Indexes Includes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
AddDefaultCharset UTF-8

(as you see, I use only utf-8)

=== .htaccess ===
SetHandler python-program
PythonHandler mod_python.publisher

#debug on
PythonDebug On

<Files ~ "\.db?$">
    Order allow,deny
    Deny from all
</Files>

DirectoryIndex icr.py

=== icr.py ===
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#all your base is 5th

import re, string
from mx.DateTime import now
import icrBackend

import icrConfig
import icrHelp

#threadsafe locking
class __locked__:
    lock=False


th_index=__locked__()

def index(req):
  if not th_index.lock:
    #threadsafe locking, may work for apache 2
    th_index.lock=True
    __doc__="main handler"
    #default the parameter from the request handler
    param=dict(req.form)
    #...another 500 lines...
    #unlock thread
    th_index.lock=False
    return " " #mp weirdness, don't ask me why


freek sanders 06-29-2005 02:43 AM

I tried, and got this:

Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 193, in Dispatch
result = object(req)

File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line 133, in handler
module = apache.import_module(module_name, _req, [path])

File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 335, in import_module
module = imp.load_module(mname, f, p, d)

File "/var/www/icr.py", line 6, in ?
from mx.DateTime import now

ImportError: No module named mx.DateTime

codec 06-29-2005 07:35 AM

if you see those message, it is working now!

my program use mxDateTiem and pysqlite but you may not need them.
try to replace icr.py with these lines.

Code:

def index(req):
    req.content_type="text/html"
    req.send_http_header()
    req.write("<html>All your base are belong to python!</html>")
    return " "


freek sanders 06-29-2005 02:32 PM

It works, thanks al lot !

( now I'm gonna find out why it now does work )

codec 06-30-2005 04:35 PM

it wasn't working because you have not enable mod_python in /etc/apache/modules.conf, by running dpkg-reconfigure apache you did it.

In post #3, the messages you mentioned is actually debug code, it was running correctly


All times are GMT -5. The time now is 12:06 PM.