mechanize and Content Encoding Error

L

Luis G.

Hello guys.

I'm trying to get some files from a webpage using Mechanize. Something
like this:

begin
Timeout::timeout(25){
res = agent.get(torrent_download).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

(http://support.mozilla.com/en-US/kb/error loading web sites#w_content-encoding-error)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,961
Messages
2,570,131
Members
46,689
Latest member
liammiller

Latest Threads

Top