Python with Apache
MRAB
python at mrabarnett.plus.com
Mon Apr 15 22:38:21 EDT 2013
On 16/04/2013 03:02, Renato Barbosa Pim Pereira wrote:
> I am trying to execute cgi101.py:
>
> #!/usr/bin/python
>
> import cgi
>
> form = cgi.FieldStorage() # parse form data
> print('Content-type: text/html\n') # hdr plus blank line
> print('<title>Reply Page</title>') # html reply page
> if not 'user' in form:
> print('<h1>Who are you?</h1>')
> else:
> print('<h1>Hello <i>%s</i>!</h1>' % cgi.escape(form['user'].value))
>
> I have installed mod_python do apache2 and created one entry in
> /etc/apache2/sites-available/default:
>
> DocumentRoot /var/www
> <Directory /var/www/py/>
> AddHandler mod_python .py
> PythonHandler cgi101
> PythonDebug On
> </Directory>
>
> What. happen is: when i call this file on browser I have the following
> error:
> Can someone help?
>
> MOD_PYTHON ERROR
>
> ProcessId: 2742
> Interpreter: '127.0.1.1'
>
> ServerName: '127.0.1.1'
> DocumentRoot: '/var/www'
>
> URI: '/py/cgi101.py'
> Location: None
> Directory: '/var/www/py/'
> Filename: '/var/www/py/cgi101.py'
> PathInfo: ''
>
> Phase: 'PythonHandler'
> Handler: 'cgi101'
>
> Traceback (most recent call last):
>
> File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch
> default=default_handler, arg=req, silent=hlist.silent)
>
> File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1206, in _process_target
> object = apache.resolve_object(module, object_str, arg, silent=silent)
>
> File "/usr/lib/python2.7/dist-packages/mod_python/apache.py", line 696, in resolve_object
> raise AttributeError, s
>
> AttributeError: module '/var/www/py/cgi101.py' contains no 'handler'
>
>
> MODULE CACHE DETAILS
>
> Accessed: Mon Apr 15 22:02:42 2013
> Generation: 0
>
> _mp_63ea7b6576c7d3a5f48ef8741e8048b0 {
> FileName: '/var/www/py/cgi101.py'
> Instance: 1 [IMPORT]
> Generation: 1
> Modified: Mon Apr 15 21:52:27 2013
> Imported: Mon Apr 15 22:02:42 2013
> }
>
I think it's looking for a function called 'handler' in the module
'cgi101.py'.
This might help you:
http://www.modpython.org/live/mod_python-2.7.8/doc-html/tut-overview.html
More information about the Python-list
mailing list