[twill] posting without a form?
iainduncan at telus.net
Sun Dec 2 22:11:11 PST 2007
On Mon, 2007-03-12 at 00:09 -0600, Ian Bicking wrote:
> Titus Brown wrote:
> > On Sun, Dec 02, 2007 at 04:03:46PM -0800, iain duncan wrote:
> > -> Hey guys, wondering if I can do an arbitrary post from twill using all
> > -> the handy shortcuts if the form I want to pretend to be does *not*
> > -> exist.
> > ->
> > -> Ie, from a python method I want to post a set of key/vals to an
> > -> arbitrary url, but use twill commands. I didn't see this in the
> > -> examples.
> > ->
> > -> Thanks!
> > -> Iain
> > hi Iain,
> > I don't know exactly how to do this with twill (or, more importantly,
> > with mechanize -- getting twill to do it would be easy, given mechanize
> > functionality). It shouldn't be too hard, however.
> > Note that this is of great value for testing AJAX code, too.
> In case you aren't sure about what it looks like, a POST form is just a
> submission with a url-encode body (assuming you aren't doing file
> uploads, which are harder).
> In urllib/urllib2, if you do a POST you give the body as an argument,
> with urllib.urlencode(form_values) as the body. form_values can be a
> dict, or better a list of (key, value) tuples.
Thanks Ian, I appreciate the tip. As it happens I did know about doing
it that way, and wound up doing just that, but I thought it might be a
nice addition to twill given the supereasy twill syntax as compared to
the easy urllib/urllib2 syntax!
More information about the twill