[Tutor] CGI, Apache (and ODBC?)
Jeff Childers
jchilders@smartITservices.com
Thu, 5 Sep 2002 09:06:11 -0400
Hi all, got a wierd one.
When I run my python routine from the command line, it works properly. I can
pipe the output to a temporary html file and open it in the browser, works
fine. But when I try to run it as a CGI, it returns the following (apache's
error log):
"mxODBC.OperationalError: ('IM002', 0, '[Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified', 5998)"
I've pasted the code that handles the ODBC below if it helps. Does anyone
have any idea where I should start looking? I thought the CGI process ran
the same Python.EXE that I get from the command line?
Thanks,
Jeff
#!python.exe
# showitems.py
# CGI Program to display Inventory Items in HTML Table
import os
import cgi
import pro_ODBC
class doIt:
def printheader(self, title):
print """Content-type: text/html
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns = "http://www.w3.org/1999/xhtml">
<head><title>%s</title></head>
<body>""" % title
def main(self):
rowNumber = 0
backgroundColor = "white"
items = pro_ODBC.proItems()
items.getItems()
self.printheader("Item List")
print """<table style = "border: 0">"""
#print table of CGI vars
for item in items.itemList.keys():
rowNumber += 1
if rowNumber % 2 == 0:
backgroundColor = "white"
else:
backgroundColor = "lightgrey"
print """<tr style = 'background-color: %s'>""" % backgroundColor,
#table2 = """<td>%s</td><td>%s</td></tr>""" % ("foo", "bar")
table2 = """<td>%s</td><td>%s</td></tr>""" % (cgi.escape(item),
cgi.escape( items.itemList[item]))
print table2
print """</table></body></html>"""
def startup():
o = doIt()
o.main()
if __name__ == "__main__":
startup()
# PRO_ODBC.PY
# Connect to SQL, make dictionary for output
import mx.ODBC.Windows
import time
class proItems:
def __init__(self):
self.db = mx.ODBC.Windows.DriverConnect("DSN=Pro Series 6.5")
self.itemList = {}
def getItems(self):
# Start Querying
cur = self.db.cursor()
# Get items
cur.execute("SELECT * FROM ICITEM99")
counter = 1
while (1):
item = cur.fetchone()
if item == None:
break
self.itemList[item[0]] = item[1]
counter += 1
cur.close()
def closeDB(self):
self.db.close()
print "Closed."