[twill] Twill and HTTP headers

Kevin Boers KBoers at leapfrogonline.com
Mon Jun 7 15:12:04 PDT 2010

Hi, Mike,

It's pretty easy to print the response headers using the info() method:

>>> import twill.commands as twill
>>> twill.go('http://path/to/json_file.json')
>>> twill.info<http://twill.info>()

Page information:
URL: http://path/to/json_file.json
HTTP code: 200
Content type: application/json; charset=utf-8
It's not super straightforward, but you can also grab the response headers from the browser object as well (for example, if you want to assert against them):

>>> b = twill.get_browser()
>>> b._browser._response.info().getheaders("content-type")
['application/json; charset=utf-8']

Does that help?


On Jun 7, 2010, at 4:46 PM, Mike Orr wrote:

Hi there, I've been using Twill for a few months and find it a great
way to write a few basic tests to verify a site isn't broken. But I've
come across what seems to be a missing feature. How can I test an HTTP
header; e.g., to verify that a JSON response is actually
"Content-type: application/json"?

Mike Orr <sluggoster at gmail.com<mailto:sluggoster at gmail.com>>

twill mailing list
twill at lists.idyll.org<mailto:twill at lists.idyll.org>

Kevin P. Boers
QA Manager

Leapfrog Online
807 Greenwood
Evanston, IL  60201
Main 847-492-1968
Fax  847-492-1990
kboers at leapfrogonline.com<x-msg://107/kboers@leapfrogonline.com>

The document(s) accompanying this e-mail transmission, if any, and the e-mail transmittal message containing information from Leapfrog Online Customer Acquisition, LLC is confidential or privileged. The information is intended to be for the use of the individual(s) or entity(ies) named on this e-mail transmission message. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this e-mail is prohibited. If you have received this e-mail in error, please immediately delete this e-mail and notify us by telephone of the error.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/twill/attachments/20100607/497c06f7/attachment.htm>

More information about the twill mailing list