disabling redirection in twill/mechanize

83 views
Skip to first unread message

Jesse London

unread,
Apr 2, 2009, 12:09:57 PM4/2/09
to twil...@googlegroups.com
I'm in a situation where I'd like to be able to inspect the (code 302) response from a server without actually following it; and, I'd like to be able to do so using twill.  I can't find anything in twill or mechanize to optionally disable the redirect feature, and imagine that it's UserAgentBase/OpenerDirector that I need to address; but, owing to my extreme inexperience with either of these classes, and to the possibility that I'm missing something obvious and higher-level in twill and/or mechanize, I'd appreciate any help, suggestions or pointers-in-the-right-direction.

Thanks,
Jesse

Terry Peppers

unread,
Apr 2, 2009, 12:21:53 PM4/2/09
to twil...@googlegroups.com
Tricky ... maybe. Was looking through an older test suite I have:

config("acknowledge_equiv_refresh", "false")

So ...

>>> import twill.commands as tc
>>> tc.config()
current configuration:
acknowledge_equiv_refresh : True
allow_parse_errors : True
readonly_controls_writeable : False
require_BeautifulSoup : False
require_tidy : False
use_BeautifulSoup : True
use_tidy : True
with_default_realm : False

>>>

If you turn it off ... you'll see the header and won't actually follow
it. At least that's what Twill allows you to do ... but I would check
out what that config set does to Mech or the Twill Browser to halt the
auto follow.

Jesse London

unread,
Apr 2, 2009, 12:50:19 PM4/2/09
to twil...@googlegroups.com
Sure, trying twill's "acknowledge_equiv_refresh" config option makes sense, but it doesn't do the trick.

C. Titus Brown

unread,
Apr 12, 2009, 12:09:57 PM4/12/09
to twil...@googlegroups.com
On Thu, Apr 02, 2009 at 11:50:19AM -0500, Jesse London wrote:
-> Sure, trying twill's "acknowledge_equiv_refresh" config option makes sense,
-> but it doesn't do the trick.

File an issue, please ;)

--titus

-> On Thu, Apr 2, 2009 at 11:21 AM, Terry Peppers <pep...@gmail.com> wrote:
->
-> >
-> > Tricky ... maybe. Was looking through an older test suite I have:
-> >
-> > config("acknowledge_equiv_refresh", "false")
-> >
-> > So ...
-> >
-> > >>> import twill.commands as tc
-> > >>> tc.config()
-> > current configuration:
-> > acknowledge_equiv_refresh : True
-> > allow_parse_errors : True
-> > readonly_controls_writeable : False
-> > require_BeautifulSoup : False
-> > require_tidy : False
-> > use_BeautifulSoup : True
-> > use_tidy : True
-> > with_default_realm : False
-> >
-> > >>>
-> >
-> > If you turn it off ... you'll see the header and won't actually follow
-> > it. At least that's what Twill allows you to do ... but I would check
-> > out what that config set does to Mech or the Twill Browser to halt the
-> > auto follow.
-> >
-> > >
-> >
->
-> ->

--
C. Titus Brown, c...@msu.edu

Jesse London

unread,
Apr 14, 2009, 6:09:20 PM4/14/09
to twil...@googlegroups.com
If you mean file an issue regarding "acknowledge_equiv_refresh", I think I've misspoken -- I don't believe this situation is covered by that setting, as I believe that is regarding HTTP-EQUIV headers (HTTP headers embedded in HTML); it's not surprising that setting that option to False doesn't help.

Rather, I would like to be able to optionally inspect the headers of a code 302 response, rather than automatically following it.  At the moment I'm investigating extension of the mechanize HTTPRedirectHandler, e.g. overloading http_error_302, to optionally do something other than open a new, redirected, request.

Jesse

C. Titus Brown

unread,
Apr 14, 2009, 11:05:49 PM4/14/09
to twil...@googlegroups.com
On Tue, Apr 14, 2009 at 05:09:20PM -0500, Jesse London wrote:
-> If you mean file an issue regarding "acknowledge_equiv_refresh", I think
-> I've misspoken -- I don't believe this situation is covered by that setting,
-> as I believe that is regarding HTTP-EQUIV headers (HTTP headers embedded in
-> HTML); it's not surprising that setting that option to False doesn't help.
-> Rather, I would like to be able to optionally inspect the headers of a code
-> 302 response, rather than automatically following it. At the moment I'm
-> investigating extension of the mechanize HTTPRedirectHandler, e.g.
-> overloading http_error_302, to optionally do something other than open a
-> new, redirected, request.

yes, exactly so. if you get it working, great; if you want me or
someone else to take a look at it, open an issue.

cheers,
--titus

Reply all
Reply to author
Forward
0 new messages