Python cx_Oracle and Apache

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raja

    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 TestDatabaseTra ceDashboard python


    import cgi
    import sys, os
    #import cgitb;cgitb.ena ble()


    #os.environ[ 'ORACLE_HOME' ] = '/opt/app/oracle/product/10.2.0.2/
    client'
    #if os.environ.has_ key( 'LD_LIBRARY_PAT H' ):

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

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



    try:
    import cx_Oracle
    import cx_Oracle_Amazo n
    except ImportError, e:

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


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


    def test_dbconnect( ):

    connection=cx_O racle.Connectio n('suvidhak_adm in','database', 'dcrno1')
    cur=connection. cursor()
    cur.execute('se lect shipment_id from
    pending_custome r_shipments where rownum < 10')
    return cur

    cursor = test_dbconnect( )


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


    generate_output ()



    Thanks,
    Raja.
  • Hrvoje Niksic

    #2
    Re: Python cx_Oracle and Apache

    Raja <rokkamraja@gma il.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.

    Comment

    • Cousin Stanley

      #3
      Re: Python cx_Oracle and Apache

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

      Comment

      • Raja

        #4
        Re: Python cx_Oracle and Apache

        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.

        Comment

        Working...