cgi POST question

Christopher chris_mk at hotmail.com
Thu Feb 7 15:30:32 EST 2002


Hi,
     I am relatively new to programming in general and Python in
particular (Two years programming basic stuff and the last six months
with Python).  For the most part, I use Python purely to process and
extrapolate data.  I have absolutely no Network Programming
experience.  Lately, I have been using the urllib module to construct
cgi queries on the fly (get a list of keywords, etc. and plug them
into a generic cgi query).  As an example (not real code):

ListOfQueries = []
cgiQuery = "http://www.site.com/query.cgi?keyword=MYWORD&defaults=blahblah"
for x in [MyListOfStuff]:
        newQuery = cgiQuery.replace('MYWORD', x)
        ListOfQueries.append(newQuery)


I would then use the formatted queries for whatever.  My boss asked me
to add  the ability to do the same on our intranet server.  I thought
it would be easy.  I was wrong.  Here is what I think is going on
(though I am sure I have some details wrong).
     A query like the one above is what is passed when a method of
'GET' is specified (the intranet search specifies a method of 'POST'
instead, I realized much later).  I carefully constructed the cgi
query, but it wasn't returning the correct results.  I then took the
source itselt, modified it to submit using a method of 'GET' and
tried.  The cgi query that was produced matched what I had constructed
but still no results.  I spoke with the guy in charge of the intranet
search engine and he said that the cgi script he wrote is incompatible
with a 'GET' method (my ignorance shows itself, I thought it didn't
matter which method was used) and he doesn't have the time or the
inclination to change it (he was also a little bitter that I would
even be 'messing' with his 'stuff' even though it was his boss' boss
that told me to do it).  I looked at the cgi module documentation, but
it doesn't seem to be able to do what I want.
     What I want, by the way, is to know if there is a python module
that submits information in the 'POST' method.  With urllib, I can
submit information in the 'GET' method (all it is is a website, after
all), but I can't figure out how to do the same with the POST method
(I was thinking it would be an object, with attributes in a dictionary
and a method to post it to the cgi script in the correct format,
soemthing like:

myTest = cgimodule.cgiPostObject
myTest['keyword'] = "MyWord"
myTest['keyword2'] = "MyOtherWord"
myTest.cgiSubmit("http://www.site.com/query.cgi", method = 'POST')


or something to that effect).  I would write it myself, but I wouldn't
know how.
     I did have my boss approve the purchases of a couple networking
books and "Python Web Programming" by Steve Holden (<= very good so
far, btw) but I am still not up to speed yet (basically, I am learning
Networking stuff, but reading at home, since I am so busy at work).  I
really need to figure this out because patience is relatively low
right now.  Any help would be appreciated.  Thank you very much.  I
would be happy to answer any additional questions. Talk to you all
later.

Chris



More information about the Python-list mailing list