Python cx_Oracle and Apache

R

Raja

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.
 
H

Hrvoje Niksic

Raja said:
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.

Look at the server's error log to see what the real error message is.
You are probably missing an environment variable such as ORACLE_HOME.
 
C

Cousin Stanley

....

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

generate_output()

Raja ....

You might try adding a Content-type header followed by
a blank line to your generate_output() function ....

def generate_output() :
print 'Content-type: text/html'
print
print .... rest of your html ....
 
R

Raja

  Raja ....

    You might try adding a  Content-type  header followed by
    a  blank line  to your  generate_output()  function ....

    def generate_output() :
        print 'Content-type:  text/html'
        print                              
        print .... rest of your html ....

Hi,
Thanks for the help. I actually got the solution. The problem was
apache's timeout is set to 1second. I just changed that value and it
worked.


Thanks,
Raja.
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top