[twill] setting HTTP headers

Titus Brown titus at caltech.edu
Wed Dec 20 16:18:23 PST 2006


On Wed, Dec 20, 2006 at 03:28:54PM -0800, Shaun Walbridge wrote:
-> Hi list,
-> 
-> I'm currently using twill to build a basic Campfire API, and am quite 
-> happy with its cookie and form handling.  I's also like to set http 
-> headers to my requests, is there an easy way to do this? With urllib2, 
-> it'd be something like:
-> 
-> import urllib2
-> headers = {'X-Requested-With' : 'XMLHttpRequest'}
-> response = opener.open(urllib2.Request(url, data, headers))
-> 
-> Is there any easy way of wrapping twill to do the same thing?

Hi, Shaun,

try

import twill
b = twill.get_browser()
b._browser.addheaders += [('X-Requested-With', 'XMLHttpRequest')]

This or something like it should work -- see 'twill/browser.py'.
I'll put in a command to do this directly when I get back.

--titus



More information about the twill mailing list