apache can't handle *.py files

apache can't handle *.py files

system:
Apache/2.2.8 (Ubuntu) mod_python/3.3.1 Python/2.5.2 PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch configured

conf:
/etc/apache2/mods-enabled/mod_python.load

LoadModule python_module /usr/lib/apache2/modules/mod_python.so


/etc/apache2/httpd.conf:

<Directory /var/www>
    AddHandler mod_python .py
    PythonHandler mptest
    PythonDebug On
</Directory>

log:
[Fri Aug 22 16:35:15 2008] [notice] mod_python: Creating 8 session mutexes based on 150 max processes and 0 max threads.
[Fri Aug 22 16:35:15 2008] [notice] mod_python: using mutex_directory /tmp
[Fri Aug 22 16:35:15 2008] [notice] Apache/2.2.8 (Ubuntu) mod_python/3.3.1 Python/2.5.2 PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch configured -- resuming normal operations


为什么浏览test.py,文件不能被解释,出现下载对话框。


大家帮忙了。。。。。

<Directory "/usr/python">
    AddHandler mod_python .py
    PythonHandler mod_python.publisher
    PythonDebug On
</Directory>

我服务器配置是这个样子的,都可以正常使用的哦。
你可以看下我博客里安装配置mod_python的帖子:
http://xiaoyu9805119.blog.163.co ... 156200731932353684/

我也发在cu了:
http://bbs.chinaunix.net/thread-1198737-1-1.html

源代码:
from mod_python import apache

def handler(req):
    req.content_type = ’text/plain’
    req.write("Hello World!")
    return apache.OK
报错内容:

MOD_PYTHON ERROR

ProcessId:      6075
Interpreter:    '127.0.1.1'

ServerName:     '127.0.1.1'
DocumentRoot:   '/var/www/'

URI:            '/mptest.py'
Location:       None
Directory:      '/var/www/'
Filename:       '/var/www/mptest.py'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'mod_python.publisher'

Traceback (most recent call last):

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1229, in _process_target
    result = _execute_target(config, req, object, arg)

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1128, in _execute_target
    result = object(arg)

  File "/usr/lib/python2.5/site-packages/mod_python/publisher.py", line 204, in handler
    module = page_cache[req]

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1059, in __getitem__
    return import_module(req.filename)

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 296, in import_module
    log, import_path)

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 680, in import_module
    execfile(file, module.__dict__)

  File "/var/www/mptest.py", line 6

SyntaxError: Non-ASCII character '\xe2' in file /var/www/mptest.py on line 6, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details (mptest.py, line 6)


MODULE CACHE DETAILS

Accessed:       Sat Aug 23 14:54:50 2008
Generation:     1

_mp_62f567356a006b1ae45f4237c31730db {
  FileName:     '/var/www/mptest.py'
  Instance:     1 [IMPORT]
  Generation:   0 [ERROR]
  Modified:     Fri Aug 22 20:46:18 2008
}
谢了

好像能调用了
可好像还是有问题


QUOTE:
原帖由 jutang 于 2008-8-23 14:57 发表
源代码:
from mod_python import apache

def handler(req):
    req.content_type = ’text/plain’
    req.write("Hello World!")
    return apache.OK
报错内容:

MOD_PYTHON ERROR

Process ...

这个应该是编码问题,在文件前面指定编码试试。