LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices

Reply
 
Search this Thread
Old 06-27-2005, 03:38 PM   #1
freek sanders
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Rep: Reputation: 0
[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?
 
Old 06-28-2005, 06:50 PM   #2
codec
Member
 
Registered: Sep 2003
Location: mad.es.eu
Distribution: ubuntu 5.04 knoppix Slack91/10 freebsd51 vector4 redhat9
Posts: 304

Rep: Reputation: 30
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

Last edited by codec; 06-28-2005 at 07:06 PM.
 
Old 06-29-2005, 03:43 AM   #3
freek sanders
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Original Poster
Rep: Reputation: 0
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
 
Old 06-29-2005, 08:35 AM   #4
codec
Member
 
Registered: Sep 2003
Location: mad.es.eu
Distribution: ubuntu 5.04 knoppix Slack91/10 freebsd51 vector4 redhat9
Posts: 304

Rep: Reputation: 30
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 " "
 
Old 06-29-2005, 03:32 PM   #5
freek sanders
LQ Newbie
 
Registered: Sep 2004
Posts: 17

Original Poster
Rep: Reputation: 0
It works, thanks al lot !

( now I'm gonna find out why it now does work )
 
Old 06-30-2005, 05:35 PM   #6
codec
Member
 
Registered: Sep 2003
Location: mad.es.eu
Distribution: ubuntu 5.04 knoppix Slack91/10 freebsd51 vector4 redhat9
Posts: 304

Rep: Reputation: 30
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
libapache-mod-cgi-debug in debian sarge rblampain Debian 1 11-04-2005 11:34 PM
How to check a Python tape drive on Debian? avantman42 Linux - Hardware 4 03-14-2005 06:00 PM
idle for python not working bingbang Linux - Newbie 0 03-28-2004 08:44 AM
Python with MySQL/PostgreSQL not working iainr Programming 2 02-03-2004 03:50 PM
python: import distutils fails on debian? jpbarto Linux - Software 0 01-18-2004 11:36 AM


All times are GMT -5. The time now is 05:37 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration