Afficher un message
Vieux 08/02/2008, 01h48   #1
pythonbrian
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut No such file or directory .... ??? Configuration Error

I am new to apache but I am learning quickly but recently I have been
trying to learn database interaction. I developed a simple python
script but I keep getting an error message (internal server error 500)
when I load the web page. The apache error log file shows the
following information and my permissions on the file appear to be
okay. I think I have a configuration problem in apache but I don't
know what to do ... any thoughts:

--------------------------------------------------------------------

[Thu Feb 07 15:49:50 2008] [error] [client 127.0.0.1] (2)No such file
or directory: exec of '/var/www/cgi-bin/fig17_27.py' failed
[Thu Feb 07 15:49:50 2008] [error] [client 127.0.0.1] Premature end of
script headers: fig17_27.py

--------------------------------------------------------------------

brxxxxsh@ubuntu:/var/www/cgi-bin$ ls -al fig17_27.py
-rwxr-xr-x 1 root root 3488 2008-02-07 15:49 fig17_27.py

--------------------------------------------------------------------

Contents of file: fig17_27.py (this executes fine from the command
line using the command: "python fig17_27.py" and I see data from the
database, so I am assuming the program/script is okay.
Also, this is a example/tutorial from a Deitel text book ...

#!/usr/local/bin/python
# Fig. 17.27: fig17_27.py
# Displays contents of the Authors table,
# ordered by a specified field.

import MySQLdb
import cgi
import sys

def printHeader( title ):
print """Content-type: text/html

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml"
xml:lang = "en" lang = "en">
<head><title>%s</title></head>

<body>""" % title

# obtain user query specifications
form = cgi.FieldStorage()

# get "sortBy" value
if form.has_key( "sortBy" ):
sortBy = form[ "sortBy" ].value
else:
sortBy = "firstName"

# get "sortOrder" value
if form.has_key( "sortOrder" ):
sortOrder = form[ "sortOrder" ].value
else:
sortOrder = "ASC"

printHeader( "Authors table from Books" )

# connect to database and retrieve a cursor
try:
connection = MySQLdb.connect( db = "Books", user = "root" )

# error connecting to database
except MySQLdb.OperationalError, error:
print "Error:", error
sys.exit( 1 )

# retrieve cursor
else:
cursor = connection.cursor()

# query all records from Authors table
cursor.execute( "SELECT * FROM Authors ORDER BY %s %s" %
( sortBy, sortOrder ) )

allFields = cursor.description # get field names
allRecords = cursor.fetchall() # get records

# close cursor and connection
cursor.close()
connection.close()

# output results in a table
print """\n<table border = "1" cellpadding = "3" >
<tr bgcolor = "silver" >"""

# create table header
for field in allFields:
print "<td>%s</td>" % field[ 0 ]

print "</tr>"

# display each record as a row
for author in allRecords:
print "<tr>"

for item in author:
print "<td>%s</td>" % item

print "</tr>"

print "</table>"

# obtain sorting method from user
print """
\n<form method = "post" action = "/cgi-bin/fig17_27.py">
Sort By:<br />"""

# display sorting options
for field in allFields:
print """<input type = "radio" name = "sortBy"
value = "%s" />""" % field[ 0 ]
print field[ 0 ]
print "<br />"

print """<br />\nSort Order:<br />
<input type = "radio" name = "sortOrder"
value = "ASC" checked = "checked" />
Ascending
<input type = "radio" name = "sortOrder"
value = "DESC" />
Descending
<br /><br />\n<input type = "submit" value = "SORT" />
</form>\n\n</body>\n</html>"""


  Réponse avec citation
 
Page generated in 0,07439 seconds with 9 queries