views:

44

answers:

2

I use the module mechanize in order to log in a site. When I import twill.commands without any other apparent use, some debug messages [0] are displayed [1]. When I delete it, these messages disappear.

How can I see what is changed in the environment in order to emulate it and remove this dependency?

[0] Using the logging module. [1] More specifically, I am interested in a Following HTTP-EQUIV=REFRESH message.

UPDATE: It turned out that there is a bug in twill.commands which was creating an error when trying to follow the HTTP-EQUIV=REFRESH header. After removing the import twill.commands and the ugly work around it, everything works smoothly.

+1  A: 

My guess - without digging in the libraries - is that twill is instantiating a logger, and mechanize is doing the Right Thing for a library, logging if logging has been turned on, not if not.

To enable the logging of mechanize configure a logging.basicConfig root in your application code.

msw
+1  A: 

twill uses mechanize internally, you can log into a web site directly with twill.

To follow http-equiv redirection, just use the go command.

go <url> -- visit the given URL. The Python function returns the final URL visited, after all redirects.

To debug http-equiv redirects, enable the relevant debug level.

debug <what> <level> -- turn on or off debugging/tracing for various functions. The first argument is either 'http' to show HTTP headers, 'equiv-refresh' to test HTTP EQUIV-REFRESH headers, or 'commands' to show twill commands. The second argument is '0' for off, '1' for on.

gimel
When the `twill` is imported, I can't follow the `http-equiv` redirection using the `go` command. It always raises an exception about urllib...
myle
Works here. Try installing latest twill from http://code.google.com/p/twill/source/checkout
gimel
I have to use the version in Debian archives, which admittedly is rather old.
myle