469,602 Members | 1,823 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Python cx_Oracle and Apache

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.
Aug 25 '08 #1
3 2141
Raja <ro********@gmail.comwrites:
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.
Aug 25 '08 #2
....

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 ....
--
Stanley C. Kitching
Human Being
Phoenix, Arizona

Aug 25 '08 #3
On Aug 25, 1:53*pm, Cousin Stanley <cousinstan...@gmail.comwrote:
....
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 ....

--
Stanley C. Kitching
Human Being
Phoenix, Arizona
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.
Aug 25 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Bryan J Gudorf | last post: by
1 post views Thread by Maxim Kuleshov | last post: by
7 posts views Thread by vb_bv | last post: by
4 posts views Thread by hot.favorite | last post: by
reply views Thread by cirudinezidane | last post: by
reply views Thread by M.-A. Lemburg | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.