[Tutor] Best way to POST XML to CGI

Ertl, John C CIV 63134 john.ertl at navy.mil
Thu Jun 7 17:22:44 CEST 2007


All,

I have a Python program that makes images of data and I want to be able to make these via a web interface.  I want to keep it simple so I thought I would send an XML file to a cgi program (XML is what I am supposed to use).  I have the parsing of the XML all figured out but the way I am sending the XML and receiving it does not look like they are the best ways.

I have an HTML form that I use to collect input on what kind of image.   I then take that form input and make it into an XML string.  I then take that XML string and POST it to a CGI script.

I am using cgi to retrieve the XML string.  Once I have the string I get the needed info and make an image.  The Part that just does not look right to me is using form = cgi.FieldStorage()

Of someone else wanted to just post an XML string they would have to have the same form name "XMLhttp" that is not very user friendly.   My guess is I am missing something about how cgi can work.

I bet Python has a simple way to receive a XML post so I do not have to look for a specific form name?

Any help would be appreciated.

Thanks,

John 

 

Web page code to post XML in a text area

<form action="http://......../cgi-bin/parsXML2.py" target=text/xml method=post>
<TEXTAREA cols=60 name="XMLhttp" rows=20 wrap=Real>

<?xml version="1.0" ?>

<StatRequest requestID="user-20070531-Time"> 

</StatRequest>


</TEXTAREA> <INPUT type=submit value="Submit Query">
</FORM>

Code that receives the XML POST

    form = cgi.FieldStorage()
    if not (form.has_key("XMLhttp")):
        print "content-type: text/html\n\n"
        print "<H1>Error</H1>"


   else:
        xmlString = form["XMLhttp"].value
        print "content-type: text/html\n\n"
        req = ParseXML()


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070607/07331bce/attachment.htm 


More information about the Tutor mailing list