Using CGI module with 'canned queries' 
Author Message
 Using CGI module with 'canned queries'

Hello,

I want to use python to implement some CGI scripts. I want these
scripts to be callable from any link (not only via a form),
e.g. the user shall be able to enter something like

http://.../test.py?name=Bill

into Netscape directly.

I expected that such a URL could be processed using

    form = cgi.FieldStorage()    print '<UL>'
    for k in form.keys:
        print '<LI>' % k % ':' % form[k] % '</LI>'

(after printing an html header of course).

However, the dictionary seems to be empty when the http daemon
starts my script.

How do I access parameters within the script if not started via a form?

Lars



Sun, 06 Oct 2002 03:00:00 GMT  
 Using CGI module with 'canned queries'

Quote:

> Hello,

> I want to use Python to implement some CGI scripts. I want these
> scripts to be callable from any link (not only via a form),
> e.g. the user shall be able to enter something like

> http://.../test.py?name=Bill

> into Netscape directly.

The parameter(s) should still be received correctly in the CGI script.

Quote:
> I expected that such a URL could be processed using

>     form = cgi.FieldStorage()    print '<UL>'
>     for k in form.keys:
>         print '<LI>' % k % ':' % form[k] % '</LI>'

Surely you mean...

          print '<LI>' + k + ':' + form[k].value + '</LI>'

Quote:
> (after printing an html header of course).

> However, the dictionary seems to be empty when the http daemon
> starts my script.

Are you sure that the problem doesn't lie in the fact that form[k] is not likely
to be a string, but a FieldStorage object instead? Thus, you must refer to the
value attribute of form[k].

Quote:
> How do I access parameters within the script if not started via a form?

You should be able to do just that with the 'cgi' module.

Paul



Sun, 06 Oct 2002 03:00:00 GMT  
 Using CGI module with 'canned queries'

Paul,

The %'s were obviously wrong, but they got mixed up when I
transferred the string from '%s:%s...' % (a,b,c) into the e-mail
where I wrote some bogus stuff.

Indeed I overlookes the .value attribute of the keys.

Thanks,
Lars

Quote:
Paul Boddie writes:


 > >
 > > Hello,
 > >
 > > I want to use Python to implement some CGI scripts. I want these
 > > scripts to be callable from any link (not only via a form),
 > > e.g. the user shall be able to enter something like
 > >
 > > http://.../test.py?name=Bill
 > >
 > > into Netscape directly.
 >
 > The parameter(s) should still be received correctly in the CGI script.
 >
 > > I expected that such a URL could be processed using
 > >
 > >     form = cgi.FieldStorage()    print '<UL>'
 > >     for k in form.keys:
 > >         print '<LI>' % k % ':' % form[k] % '</LI>'
 >
 > Surely you mean...
 >
 >           print '<LI>' + k + ':' + form[k].value + '</LI>'
 >
 > > (after printing an html header of course).
 > >
 > > However, the dictionary seems to be empty when the http daemon
 > > starts my script.
 >
 > Are you sure that the problem doesn't lie in the fact that form[k] is not likely
 > to be a string, but a FieldStorage object instead? Thus, you must refer to the
 > value attribute of form[k].
 >
 > > How do I access parameters within the script if not started via a form?
 >
 > You should be able to do just that with the 'cgi' module.
 >
 > Paul
 > --
 > http://www.python.org/mailman/listinfo/python-list
 >


Sun, 06 Oct 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. It's not bad canned meat...

2. It's not bad canned meat...

3. It's not bad canned meat...

4. It's not bad canned meat...

5. Importing modules for cgi's

6. I don't want characters translated in query using http::geturl

7. can't find module 'GL'

8. Object Rexx problems with cgi's when using IBM internet connection server

9. Regina stream('Query exists') bug

10. Query on 'n ' dimensional arrays

11. changing the php '?' query string identifier

12. queries in different 'environments'

 

 
Powered by phpBB® Forum Software