On Mon, Dec 03, 2007 at 12:09:12AM -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.
Ian, you're of course correct -- but part of the value of the twill/mechanize approach is getting all of the cookies etc. right. mechanize does adhere to most of the urllib2 interface, AFAIK, so you could just look at the urllib2 docs (or the "Missing Manual" that Michael Foord posted, http://www.voidspace.org.uk/python/articles/urllib2.shtml) for inspiration. --titus _______________________________________________ twill mailing list [email protected] http://lists.idyll.org/listinfo/twill
