Apache & Python 500 Error

C

Christian

Hello,

i have an apache 1.3 server with python on debian. Python works fine but
the scripts wont´t work.

This easy script i want to do on apache:

#!/usr/bin/python
import os
os.getcwd()

in apache config i have done this:

<Directory /var/www/python>
AddHandler python-program .py
PythonHandler python
Order allow,deny
Allow from all
#PythonDebug On
</Directory>

the script is in this directory /var/www/python

but i get an 500 error everytime, with "every" script - why that - i´m
newbie - sorry for that :)

greetings from germany to newsgroup
christian
 
J

Jeremy Bowers

Hello,

i have an apache 1.3 server with python on debian. Python works fine but
the scripts wont´t work.

I know what your problem is.

But first, check your apache error log. Then you will know what your error
is, too.

If you can't fix it after you try to fix the error in the log, or you
don't understand the log entry, post your program and all relevant log
entries. You did good posting your Apache configuration, but we also need
the log entries.

That said, fuzzyman is right, but keep this in mind for future help
requests.
 
C

Christian

Jeremy said:
But first, check your apache error log. Then you will know what your error
is, too.

Thanks for help, here is my error log:

[Thu Feb 3 13:52:49 2005] [error] PythonHandler python: Traceback (most
recent call last):
[Thu Feb 3 13:52:49 2005] [error] PythonHandler python: File
"/usr/lib/python2.3/site-packages/mod_python/apache.py", line 181, in
Dispatch\n module = import_module(module_name, _req)
[Thu Feb 3 13:52:49 2005] [error] PythonHandler python: File
"/usr/lib/python2.3/site-packages/mod_python/apache.py", line 335, in
import_module\n module = imp.load_module(mname, f, p, d)
[Thu Feb 3 13:52:49 2005] [error] PythonHandler python: File
"/var/www/python/python.py", line 1
[Thu Feb 3 13:52:49 2005] [error] PythonHandler python: from
mod_python import apache
[Thu Feb 3 13:52:49 2005] [error] PythonHandler python: ^
[Thu Feb 3 13:52:49 2005] [error] PythonHandler python: SyntaxError:
invalid syntax

----
My test script:
#!/usr/bin/python

print 'Content-Type: text/plain\r'
print '\r'
import os
print os.getcwd()

thanks to Fuzzyman for test script
 
P

Peter van Kampen

Hello,

i have an apache 1.3 server with python on debian. Python works fine but
the scripts wont´t work.

This easy script i want to do on apache:

#!/usr/bin/python
import os
os.getcwd()

in apache config i have done this:

<Directory /var/www/python>
AddHandler python-program .py
PythonHandler python
Order allow,deny
Allow from all
#PythonDebug On
</Directory>

the script is in this directory /var/www/python

but i get an 500 error everytime, with "every" script

You're confusing mod_python and cgi. And you're cgi isn't written
properly...

Try this to enable cgi for python files:

<Directory /var/www/python>
Options +ExecCGI
AddHandler cgi-script py
</Directory>

Don't forget to restart apache.

A proper cgi-file outputs a header with at least the content-type. A
header is followed by an empty line.

#!/usr/bin/env python

import os

print "Content-type: text/html"
print
print os.getcwd()
 
J

Jeremy Bowers

from mod_python import apache
^
SyntaxError: invalid syntax

----
My test script:
#!/usr/bin/python

print 'Content-Type: text/plain\r'
print '\r'
import os
print os.getcwd()

For the quote of the error message, I've taken the liberty of stripping
off the apache-added stuff off the front so you can read it better.

You should now be able to easily see that the error message and your shown
program don't mesh. That error appears to be from an earlier run.

Even so, I can tell you one thing: The error resulted from indenting your
"from mod_python import apache" call that you no longer have. Python uses
whitespace for structure, and just as you must indent the body of loops,
you must *not* extraneously indent other things (line continuations
don't count).

You'll need to post the correct error message after configuring Apache for
CGI as Peter showed, unless of course you figure out the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,219
Messages
2,571,117
Members
47,730
Latest member
scavoli

Latest Threads

Top