Hello guys.
I’m trying to get some files from a webpage using Mechanize. Something
like this:
begin
Timeout::timeout(25){
res = agent.get(remote_file).save_as(filename)
}
rescue SocketError => e
log.error ‘Fail saving the file ‘+filename+’: SocketError’
end
rescue SystemCallError => e
log.error ‘Fail saving the file ‘+filename+’: SystemCallError’
end
rescue Timeout::Error => e
log.error ‘Fail saving the file ‘+filename+’ Timeout::Error’
end
rescue Net::HTTPBadResponse => e
log.error ‘Fail saving the file ‘+filename+’ HTTPBadResponse’
end
rescue Mechanize::ResponseCodeError => e
log.error ‘Fail saving the file ‘+filename+’
Mechanize::RespError’
end
end
Everything was working perfectly till I found a page that, if we access
using browser, we get the following error:
Content Encoding Error
(Websites don't load - troubleshoot and fix error messages | Firefox Help)
When I get a page like that I get the following exception:
/var/lib/gems/1.8/gems/mechanize-1.0.0/lib/mechanize/chain/body_decoding_handler.rb:24:in
inflate': invalid stored block lengths (Zlib::DataError) from /var/lib/gems/1.8/gems/mechanize-1.0.0/lib/mechanize/chain/body_decoding_handler.rb:24:in
handle’
from
/var/lib/gems/1.8/gems/mechanize-1.0.0/lib/mechanize/chain.rb:29:in
pass' from /var/lib/gems/1.8/gems/mechanize-1.0.0/lib/mechanize/chain/handler.rb:6:in
handle’
from
/var/lib/gems/1.8/gems/mechanize-1.0.0/lib/mechanize/chain/response_reader.rb:35:in
handle' from /var/lib/gems/1.8/gems/mechanize-1.0.0/lib/mechanize/chain.rb:24:in
handle’
from
/var/lib/gems/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:543:in
fetch_page' from /usr/lib/ruby/1.8/net/http.rb:1053:in
request’
from /usr/lib/ruby/1.8/net/http.rb:2140:in reading_body' from /usr/lib/ruby/1.8/net/http.rb:1052:in
request’
from
/var/lib/gems/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:538:in
fetch_page' from /var/lib/gems/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:611:in
fetch_page’
from
/var/lib/gems/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:259:in `get’
…
How can I handle this exception?
SystemCallError shouldn’t handle all kind of exceptions, including this
one?
Any ideas?
Thanks,
Luis