[Web-SIG] IIS and Python CGI - how do I see more than just the form data?
J.D. Main
jdmain at comcast.net
Wed Apr 7 03:25:54 CEST 2010
Thanks Aaron,
I think I will explore the WSGI interface. However, I did learn a trick using
the OS Module:
import cgi, os
formfields = cgi.FieldStorage()
http_stuff = os.environ
print "Content-type: text/html"
print
print "<html>"
print "<head>"
print "<title>Raw HTTP Test</title>"
print "</head>"
print "<body>"
print formfields
print http_stuff
print "</body>"
print "</html>"
The os.environ variable is a big dictionary containing most (if not all) of the
values inside the original http GET or POST.
Best Regards,
JDM
I think you should consider using the
WSGI interface.
The WSGI interface puts all the components of a request
into a request environment dictionary which is sent as a
parameter to the function generating the response.
For example have a look at the test application
http://whiffdoc.appspot.com/tests/misc/testDebugDump?thisVar=thatValue&
thisOtherVar=ThatOtherValue
which dumps out the WSGI environment (with WHIFF extensions)
to the response. All the information you need is somewhere inside
the environment dictionary (but it's not always easy to find).
You could also look at WHIFF which helps combine some of the
features of the CGI module with the WSGI interface.
http://whiffdoc.appspot.com/
Hope that helps, -- Aaron Watters
===
% man less
less is more.
--- On Sat, 4/3/10, J.D. Main <jdmain at comcast.net> wrote:
> From: J.D. Main <jdmain at comcast.net>
> Subject: [Web-SIG] IIS and Python CGI - how do I see more than just the form data?
> To: web-sig at python.org
> Date: Saturday, April 3, 2010, 12:32 PM
> Hi Folks,
>
> I hope this question hasn't already been answered...
>
> I'm using IIS 5 and calling a python script directly in the
> URL of a request.
> Something like:
>
> http://someserver/myscript.py
>
> or even
>
> http://someserver/myscript.py?var1=something&var2=somthingelse
>
> Using the CGI module, I can certainly see and act upon the
> variables that
> are passed as GET or POST actions. What I'm
> after is something more
> low level. I want to see the entire HTTP request with
> everything inside it.
>
> Does IIS actually pass that information to the CGI
> application or does it just
> pass the variables?
>
> The intent is to write a "RESTFUL" CGI script. I need
> to actually "see" the
> URI and the parameters of the incoming request to map the
> appropriate
> action. Without short circuiting the IIS webserver,
> how would my python
> parse the following:
>
> http://someserver/someapp/someuser/someupdate?var1=Charlie
>
> Thanks in advance!
>
> JDM
>
>
> _______________________________________________
> Web-SIG mailing list
> Web-SIG at python.org
> Web SIG: http://www.python.org/sigs/web-sig
> Unsubscribe: http://mail.python.org/mailman/options/web-sig/arw1961%40yahoo.com
>
More information about the Web-SIG
mailing list