starting a cgi with params

G. Lewis lemiss at my-deja.com
Tue Jan 11 04:35:56 EST 2000


In article <387a686e.3028554 at nntpserver.swip.net>,
  ame at swipnet.se (Anders Eriksson) wrote:
> I have looked in the 'manual' and found the cgi, but somehow I don't
> understand... I want to be able to call my script from a link, i.e.
> http://yourhostname/cgi-bin/cgi.py?xxx.zip&get

It is true, most CGI tutorials (not just in python) seem to focus on Form
examples, and completely skip explaining the basics of the mechanism.

Likewise i will also skip explaining, but will give an example without using
forms, based on your sample above; changed slightly to:

    http://yourhostname/cgi-bin/cgi.py?get=xxxx.zip

Now a fake interactive python session (obviously you can't really do an
interactive session submitting to a CGI script)!

>>>import cgi
>>>fs = cgi.FieldStorage()
>>>fs.has_key("get")
1
>>>fs['get'].value
'xxxx.zip'

If you want the "get" and "xxxx.zip" as seperate arguments you will have to
put in some bogus key values for them to equal... perhaps emulate argument
numbers:

    http://yourhostname/cgi-bin/cgi.py?1=get&2=xxxx.zip

>>>fs['1'].value
'get'
>>>fs['2'].value
'xxxx.zip'

Note that, as you already seem to know, you must seperate the key=value items
with & characters. There are also other rules for escaping characters in URLs
that you may want to look up. Notably space characters are encoded as +, and
+ and = and others are escaped with %xx hex codes.











The link format above is (almost) the same as an HTML form would send using
the GET method.


>
> The cgi class seems to be form getting info from a form(?)
>
> What am I missing??
>
> >
> >by the way, what platform are you using? linux + apache?
>
> To make everything easy. The developing platform is WinNT+Xitami and
> the target platform (where the script will run) is Solaris + Apache
>
> // Anders
> PS! This is my home account thats why the user changed!
>
>

--
...


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list