[Tutor] Help: CGI Error in a Python Application

Crabtree, Chad Chad.Crabtree at nationalcity.com
Wed May 5 13:46:03 EDT 2004


> ------------------------------------------------
> CGI Error
> The specified CGI application misbehaved by not
> returning a complete set of HTTP headers. The headers
> it did return are:
> -----------------------------------------------
> 
> 
> The Python code is as below:
> 
> --------------------------------------------
> 
> #!c:\python23\python
> import cgi
> import sys,os
> import string
> import MySQLdb
> db=MySQLdb.connect(host="localhost",user="root",passwd="",db="power")
> cursor=db.cursor()
***************************
print "Content-Type: text/plain\n\n"
****************************
You need this so that the server and the browser know what to do with the
content.  Some browsers will choke others will work or not format it.  

I found this helpful when I was writing my first python cgi's
http://www.devshed.com/c/a/Python/Writing-CGI-Programs-in-Python/

> print "<html>"
> print "<head>"
> print "</head>"
> print "<body>"
> s=os.environ['QUERY_STRING']
> q=cgi.parse_qs(s)
> sname=q['txtname'].pop()
> scapacity=q['capacity'].pop()
> sstate=q['txtstate'].pop()
> sregion=q['region'].pop()
> sfre1=q['frequency1'].pop()
> sfre2=q['frequency2'].pop()
> sfre3=q['frequency3'].pop()
> sfre4=q['frequency4'].pop()
> cursor.execute("insert into
> station(name,region,capacity,state,fre1,fre2,fre3,fre4)
> values(%s,%s,%s,%s,%s,%s,%s,%s)",
> (sname,sregion,scapacity,sstate,sfre1,sfre2,sfre3,sfre4))
> 
> print "</body>"
> print "</html>"


-------------------------------------------------------------------------------------------
***National City made the following annotations
-------------------------------------------------------------------------------------------

This communication is a confidential and proprietary business communication.
It is intended solely for the use of the designated recipient(s).  If this
communication is received in error, please contact the sender and delete this
communication.
===========================================================================================



More information about the Tutor mailing list