Python cx_Oracle and Apache

Raja rokkamraja at gmail.com
Mon Aug 25 05:44:16 CEST 2008


Hi,
   I am trying to write a cgi program which would be executed on
browser with Apache server installed.

The program would make a connection to a database using cx_Oracle
module and display results on page.


The code is working fine on the command line but when executing it on
the browser i get the famouse "Premature end of script headers" error.

I went ahead and found the problem occuring exactly when the code is
asking for a connection to the database.


I am attaching the program for reference. Let me know if there is
anything I need to make changes to apache or any other way to overcome
this issue.


#!/apollo/bin/env -e TestDatabaseTraceDashboard python


import cgi
import sys, os
#import cgitb;cgitb.enable()


#os.environ[ 'ORACLE_HOME' ] = '/opt/app/oracle/product/10.2.0.2/
client'
#if os.environ.has_key( 'LD_LIBRARY_PATH' ):

 #   ld_library_path = os.environ[ 'LD_LIBRARY_PATH' ]
  #  os.environ[ 'LD_LIBRARY_PATH' ] = '%s/lib:%s' %
( os.environ[ 'ORACLE_HOME' ], ld_library_path )

#os.environ['BRAZIL_CONFIG']="--root=/apollo/env/
TestDatabaseTraceDashboard --user=oracle"



try:
    import cx_Oracle
    import cx_Oracle_Amazon
except ImportError, e:

#    sys.stdout.write( "Import error: %s" % ( e ) )


#sys.argv[0] = '/opt/app/oracle/admin/scripts/monitor-manager'


def test_dbconnect():
 
connection=cx_Oracle.Connection('suvidhak_admin','database','dcrno1')
        cur=connection.cursor()
        cur.execute('select shipment_id from
pending_customer_shipments where rownum < 10')
        return cur

cursor = test_dbconnect()


def generate_output():
        print '<html><body></body></html>'


generate_output()



Thanks,
Raja.



More information about the Python-list mailing list