[Tutor] python cgi and html streams
doug shawhan
doug.shawhan at gmail.com
Sat May 6 19:04:36 CEST 2006
On 5/5/06, Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
>
>
> > I was hoping for something magical like:
> >
> > gulp = cgi.StreamIO("
> > http://www.foo.com/cgi-bin/responder.cgi?foo=hi&bar=there&bat=buddy
> ").read()
> >
> > ... but for some reason not one of the python creators foresaw that I
> might
> > one day need them to do all the thinking, typing and other hard parts
> for
> > me! </rimshot>
>
>
> Hi Doug,
>
> Try the 'urllib' client library.
Headway! The information I was trying to recive is meant to be returned to
another cgi script in a parameter string. urllib.urlopen.geturl() gets my
information back to me:
The following is run on mywebsite.com
#!/usr/bin/env python
import urllib
parameters = urllib.urlencode
({"id":"hippiedavey","origin":"goatville","dest":"cowtown"})
info = urllib.urlopen("http://www.hillbillyheaven.org/expectorate.asp?%s
"%parameters).geturl()
print info
"
http://mywebsite.com/Database/test.py?quoteno=999&originzip=47567&destzip=47598&id=hippiedavey&netcharges=$251.73&days=2
"
I can, of course, use string methods to convert the returned request to
whatever I want, but I still don't belive this was the original intent of
the provider. :-) As it is now, I belive I'll have to create a script that
will retrieve the info string, then call another copy of itself to extract
the parameters from the info string! Not the worst fate, but it does seem to
double up my calls to the webserver.
On the other hand, I'll probably figure something else out! :-)
Thanks!
http://www.python.org/doc/lib/module-urllib.html
>
> The CGI server library is meant for servers, say, for the person who
> would be implmenting responder.cgi.
>
> If you need to do more complicated interactions as a client, then
> something like Mechanize might also do the trick:
>
> http://wwwsearch.sourceforge.net/mechanize/
>
> but I'd recommend looking into urllib first to see if it's sufficient for
> your problem.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060506/efbbdd58/attachment.html
More information about the Tutor
mailing list