[DB-SIG] Python Script to run an Oralce select statement and return the value in HTML

TonyM-Work mumatony-work at yahoo.com
Thu Jan 4 18:11:22 CET 2007


To update everyone;  I appreciate your help and contributions. 
   
  This takes the input variables [username, password, database] and returns the correct values from the command line, but I can not get it to return the values in a html page.  I’ve tried  =  import cgitb; cgitb.enable();  <%  -   %>  ; print ‘’’ ; but keep getting errors in html i.e. DLL load failed: Access is denied; or CGI header error;.   The web site has anonymous access and .py extension is allowed in IIS6. 
   
  Any ideas?   I know this is a simple single query but all I’m trying to test is the connection to an oracle database and a returned value in html.  Once this works I can continue configuring an application and server then pass it on to the end users.  Do any of you have a Oracle account and website to test this on?   
  Thanks again.
  Tony
  ##  Command line Code   ### 
   
  #! /usr/local/bin/python
  ###############################################################################
  # Oracle.pyw v1.0 Written by Matthew Helle (Hostingmh.com)support at hostingmh.com  20-OCT-2004
  #       BE CAREFUL EDITING THIS FILE, PYTHON IS INDENT SENSATIVE!!!
  #   Notes: Oracle.pyw is written in Python & used demonstrate how to connect &
  # run sql queries against a remote Oracle database.
  #This was tested on Windows and not tested on any other platform....
  # Program Location: 1.  Anywhere\Oracle.pyw
  #   Requirements: 1.  Oracle Client  2.  cx_Oracle for Python
  #   Location:  http://computronix.com/utilities.shtml
  #Oracle Error checking: 1.  None
  #   History: 1.  20-Oct-2004 Version 1.0 written by Matthew Helle
  ###############################################################################
  import string, time, cx_Oracle, 
   
  #set variables
  OraUid="NameXXX"        #Oracle User  
  OraPwd="NameXXX "       #Oracle password
  OraService="NameXXX"    #Oracle Service name From Tnsnames.ora file
   
  #get the current date
  now = string.upper(time.strftime("%d%m", time.localtime(time.time())))
   
  db = cx_Oracle.connect(OraUid + "/" + OraPwd + "@" + OraService)    #Connect to database
  c = db.cursor()                                                     #Allocate a cursor
  c.execute("select * from MIR_SYSTEM_VERSION")                       #Execute a SQL statement
   
  print "Records selected python-> Oracle:"
  print c.fetchall()  #Print all results
  c.close()           #Close the database connection
/****************************************

Chris Curvey <ccurvey at gmail.com> wrote:  I would start by adding

import cgitb; cgitb.enable()

at the top of your script.  Since "hello world" seems to work, and you can get the script to run via the command line, there's probably something different about the environment that IIS is using to execute your script.  (99% of the time, I find that it's a permissions problem.) 

Hope this helps!



  On 12/21/06, Boeing <mumatony-work at yahoo.com> wrote:    Hi all;   [Vickie thanks for your sample command line script http://d0db.fnal.gov/d0db/query.py.txt ] 
   
  I need help [I'm not a developer] but I need a python script hosted on an windows 2003 server which will query a remote Oracle database [odbc connection established] either using Oracle 9.2 or cx_Oracle [both installed on the server] but return the value of the query in an html [web - URL] page, Username; password and database will be hard coded in the script on the server, script code will not be displayed to end user. Its a simple select statement returning a html page in rows. Eventually SSL is going to be implemented. 
 
I have been able to get the command line py script to work [Vickie White's]. But not calling it through IIS 6.  I get this error: CGI Error: The specified CGI application misbehaved by not returning a complete set of HTTP headers. But the python extension has been "Allowed" in IIS and a simple "Hello World" python script works. [[ i.e. not real URLs:  http://metatest.web.mycompany.com/cgi-bin/helloworld.py]] 
Failing:  http://metatest.web.mycompany.com/cgi-bin/or3.py 
 
Sample for what I've gathered so far..
 
#!/usr/bin/python
print "Content-type: text/html\n\n";
print "<html><body>";
}
}
import     cx_Oracle
}
}
def connect():
 
    username = "typeUserNameHere" [hard coded]
    password = "typePassHere" [hard coded]
    database = "typeDataBaseHere" [hard coded]
}
Query: 
}
} 
"select * from MIR_SYSTEM_VERSION"
 
Any ideas or help [sample code] would be appreciated. 


_______________________________________________
DB-SIG maillist  -  DB-SIG at python.org
http://mail.python.org/mailman/listinfo/db-sig






-- 
I am often wrong, but I am never in doubt. 



*****************

Thank you,

Tony Muma 

"The most valuable thing you can ever give another person is Your &#39;Time’. Once you give it you can never get it back, so appreciate the time you share with others."

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/db-sig/attachments/20070104/31d6b5b4/attachment.htm 


More information about the DB-SIG mailing list