From: Alex Young Date: 2006-08-09T04:27:14+09:00 Subject: Re: mechanize timeout errors Berger, Daniel wrote: >>-----Original Message----- >>From: akanksha [mailto:akanksha.baid@gmail.com] >>Sent: Tuesday, August 08, 2006 12:45 PM >>To: ruby-talk ML >>Subject: mechanize timeout errors >> >> >>I am using mechanize for scraping some urls. >>begin >> page = agent.get(url) >>rescue >> puts "oops!!" >>end >> >>catches invalid urls etc. , but how to I handle timeout >>errors? In particular this is the error I get : >> >>request-header: accept => */* >>request-header: user-agent => WWW-Mechanize/0.5.1 >>(http://rubyforge.org/projects/mechanize/) >>/usr/local/lib/ruby/1.8/timeout.rb:54:in `rbuf_fill': >>execution expired >>(Timeout::Error) >> from /usr/local/lib/ruby/1.8/timeout.rb:56:in `timeout' >> from /usr/local/lib/ruby/1.8/timeout.rb:76:in `timeout' > > > begin > page = agent.get(url) > rescue Timeout::Error > puts "Timeout!" > raise > rescue > puts "Some other error!" > raise > end > > If you want control over the timeout value I think you'll need to > re-wrap the call to agent.get in your own timeout block: Not so: WWW::Mechanize#read_timeout= is your friend. -- A;ex