[Zope3-Users] Re: Send User-Agent header with zope.testbrowser.browser.Browser

Jeff Kowalczyk jtk at yahoo.com
Sat May 10 01:54:28 EDT 2008

On Fri, 09 May 2008 14:45:38 -0400, Benji York wrote:
> There's no way to do a custom User-Agent with just testbrowser.  The
> way to do it with mechanize is described in
> http://wwwsearch.sourceforge.net/mechanize/doc.html, which should work
> if used on the mech_browser attribute of a testbrowser instance.
> Note that the mech_browser attribute is an undocumented implementation
> detail and may disappear without warning.  Swim at your own risk, no
> lifeguard on duty.

Thank you, that does work, and the header continues to be sent with each
sucessive request:

  >>> from zope.testbrowser.browser import Browser
  >>> import mechanize
  >>> mech_browser = mechanize.Browser()
  >>> mech_browser.addheaders = [("User-agent", "Zope Test Browser"),]
  >>> b = Browser(mech_browser=mech_browser)
  >>> b.open('http://localhost/')

Understood that Browser.mech_browser is an undocumented implementation
detail. However, perhaps would it be appropriate to document that while
"The browser can send arbitrary headers", it won't send this particular
header without this workaround.

Hopefully if and when the implementation-detail mechanize.Browser
attribute is removed, that documentation and a test will preserve the
capability to send a custom User-agent header.


More information about the Zope3-users mailing list