Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby Net::HTTP time out
    primarykey
    data
    text
    <p>I'm trying to write my first Ruby program, but have a problem. The code has to download 32 MP3 files over HTTP. It actually downloads a few, then times-out.</p> <p>I tried setting a timeout period, but it makes no difference. Running the code under Windows, Cygwin and Mac OS X has the same result.</p> <p>This is the code:</p> <pre><code>require 'rubygems' require 'open-uri' require 'nokogiri' require 'set' require 'net/http' require 'uri' puts "\n Up and running!\n\n" links_set = {} pages = ['http://www.vimeo.com/siai/videos/sort:oldest', 'http://www.vimeo.com/siai/videos/page:2/sort:oldest', 'http://www.vimeo.com/siai/videos/page:3/sort:oldest'] pages.each do |page| doc = Nokogiri::HTML(open(page)) doc.search('//*[@href]').each do |m| video_id = m[:href] if video_id.match(/^\/(\d+)$/i) links_set[video_id[/\d+/]] = m.children[0].to_s.split(" at ")[0].split(" -- ")[0] end end end links = links_set.to_a p links cookie = '' file_name = '' open("http://www.tubeminator.com") {|f| cookie = f.meta['set-cookie'].split(';')[0] } links.each do |link| open("http://www.tubeminator.com/ajax.php?function=downloadvideo&amp;url=http%3A%2F%2Fwww.vimeo.com%2F" + link[0], "Cookie" =&gt; cookie) {|f| puts f.read } open("http://www.tubeminator.com/ajax.php?function=convertvideo&amp;start=0&amp;duration=1120&amp;size=0&amp;format=mp3&amp;vq=high&amp;aq=high", "Cookie" =&gt; cookie) {|f| file_name = f.read } puts file_name Net::HTTP.start("www.tubeminator.com") { |http| #http.read_timeout = 3600 # 1 hour resp = http.get("/download-video-" + file_name) open(link[1] + ".mp3", "wb") { |file| file.write(resp.body) } } end puts "\n Yay!!" </code></pre> <p>And this is the exception:</p> <pre><code>/Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/net/protocol.rb:140:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error) from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/net/protocol.rb:134:in `rbuf_fill' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/net/protocol.rb:116:in `readuntil' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/net/protocol.rb:126:in `readline' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/net/http.rb:2138:in `read_status_line' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/net/http.rb:2127:in `read_new' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/net/http.rb:1120:in `transport_request' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/net/http.rb:1106:in `request' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/open-uri.rb:312:in `block in open_http' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/net/http.rb:564:in `start' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/open-uri.rb:306:in `open_http' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/open-uri.rb:767:in `buffer_open' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/open-uri.rb:203:in `block in open_loop' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/open-uri.rb:201:in `catch' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/open-uri.rb:201:in `open_loop' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/open-uri.rb:146:in `open_uri' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/open-uri.rb:669:in `open' from /Users/test/.rvm/rubies/ruby-1.9.2-preview1/lib/ruby/1.9.1/open-uri.rb:33:in `open' from test.rb:38:in `block in &lt;main&gt;' from test.rb:37:in `each' from test.rb:37:in `&lt;main&gt;' </code></pre> <p>I'd also appreciate your comments on the rest of the code.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload