In order to analyze what went wrong when Mechanize raises an exception, you'll need a log file. Mechanize can log everything to a file, including every header passed. In order to log everything, pass a new Logger object to the Mechanize#log method.
agent = Mechanize.new do|a| a.log = Logger.new('log.txt') a.user_agent_alias = "Windows IE 6" end
However, this will indeed log everything, making for a very fat log file. If you don't need all that information, you can dial back the amount that logger will actually write to the log file. General messages are logged on the INFO level, while all the (possibly irrelevant) details are logged on the DEBUG level. Simply dial back the logger level to Logger::INFO.
log = Logger.new('log.txt') log.level = Logger::INFO agent = Mechanize.new do|a| a.log = log a.user_agent_alias = "Windows IE 6" end