|
jamestmcneill-python at yahoo.co.uk
jamestmcneill-python at yahoo.co.uk
Tue Sep 13 10:37:32 EDT 2005
Good afternoon. I wonder if someone may be able to help me get to the
starting line with mod_python? I'm trying to use PythonImport to create a
database connection which I can use for subsequent requests, and I haven't
been able to figure out how. Here's what I'm putting in httpd.conf:
PythonInterpreter maininterpreter
PythonImport mpglobals maininterpreter
<Directory "C:\Program Files\Apache Group\Apache2\htdocs\moddy">
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>
mpglobals.py is in the "C:\Program Files\Apache
Group\Apache2\htdocs\moddy" folder, and an entry in c:\python23\mp.pth
adds this to sys.path. mpglobals.py attempts to load a database connection
as global:
import kinterbasdb as fbd
con = fbd.connect(dsn='localhost:C:\Program
Files\Firebird\Firebird_1_5\examples\employee.fdb',
user='sysdba',
password='masterkey')
cur = con.cursor()
Finally, the default python handler mptest.py tries to use the connection:
def handler(req):
cur.execute('select * from EMPLOYEE order by LAST_NAME')
. . . .
return apache.OK
This throws up an error:
File "C:/Program Files/Apache Group/Apache2/htdocs/moddy/\mptest.py",
line 8, in handler
cur.execute('select * from EMPLOYEE order by LAST_NAME')
NameError: global name 'cur' is not defined
Am I anywhere near going about this the right way? Can someone please draw
me a diagram?
Regards,
Jim
++++++++++++++++++++++++++++++++++++++++++++++++++
+ If you've got a good excuse - don't use it +
++++++++++++++++++++++++++++++++++++++++++++++++++)
|