argument to python cgi script

Gabriel Genellina gagsl-py2 at
Thu Apr 10 09:28:43 CEST 2008

En Wed, 09 Apr 2008 11:14:33 -0300, syed mehdi <smmehadi at>  

> Hi Guys,
> If someone can help me in telling how can i pass arguments to python cgi
> script then that will be good.
> like if i want to pass "some argument" to my remote python script, by
> calling something like:
> http://localhost/cgi-bin/\ argument.
> What is the correct way of sending arguments in this way, and how can i
> decode/receive them in


py> args = {'some': 'argument', 'x': 1, 'z': 23.4}
py> import urllib
py> urllib.urlencode(args)

You can then use urllib.urlopen or urllib2.urlopen to send the HTTP  
request and retrieve the response.

In the server side, use cgi.FieldStorage:

form = cgi.FieldStorage()
x = form.getfirst('x', 0) # '1'
y = form.getfirst('y', 0) # '0'
z = form.getfirst('z', 0) # '23.4'

Gabriel Genellina

More information about the Python-list mailing list