From: sishen Date: 2007-06-17T02:18:51+09:00 Subject: Re: How to set the timeout attr when using open-uri to open a url. ------=_Part_57853_28341023.1182014332176 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 6/16/07, Rick DeNatale wrote: > > On 6/15/07, sishen wrote: > > Yes, i know that. Thanks. :) > > > > But i confused by the read_timeout option of the open method. > > > > > I want to set the timeout of the open process. And i see the open > method > > > has > > > > a option named "read_timeout". > > > > So i just code as > > > > open("www.abc.com", {:read_timeout => 10}). > > > > > > > > But, i can't see the effect. What's wrong with that? Any help > thanks. > > Where did you see a read_timeout option? I can't find it in any > documentation, although I might be missing something. > > Also you are opening "www.abc.com" which Kernel open is seeing as a > file name rather than a URI. Oh, sorry, it's my mistake of careless. First without open-uri > > irb(main):001:0> open("www.abc.com", {:read_timeout => 10}) > TypeError: can't convert Hash into String > from (irb):1:in `initialize' > from (irb):1:in `open' > from (irb):1 > irb(main):002:0> open("http://www.abc.com", {:read_timeout => 10}) > TypeError: can't convert Hash into String > from (irb):2:in `initialize' > from (irb):2:in `open' > from (irb):2 > > Now with open-uri What's your version? No read_timeout option of the open-uri version in Ruby 1.8. But 1.9 or openuri in rubygems has. module OpenURI Options = { :proxy => true, :proxy_http_basic_authentication => true, :progress_proc => true, :content_length_proc => true, :http_basic_authentication => true, :read_timeout => true, :ssl_ca_cert => nil, :ssl_verify_mode => nil, } irb(main):003:0> require 'open-uri' > => true > irb(main):004:0> open("www.abc.com", {:read_timeout => 10}) > TypeError: can't convert Hash into String > from /usr/local/lib/ruby/1.8/open-uri.rb:32:in `initialize' > from /usr/local/lib/ruby/1.8/open-uri.rb:32:in > `open_uri_original_open' > from /usr/local/lib/ruby/1.8/open-uri.rb:32:in `open' > from (irb):4 > > Note that there's no change since "www.abc.com" isn't a url. > > irb(main):005:0> open("http://www.abc.com", {:read_timeout => 10}) > ArgumentError: unrecognized option: read_timeout > from /usr/local/lib/ruby/1.8/open-uri.rb:103:in `check_options' > from /usr/local/lib/ruby/1.8/open-uri.rb:100:in `each' > from /usr/local/lib/ruby/1.8/open-uri.rb:100:in `check_options' > from /usr/local/lib/ruby/1.8/open-uri.rb:124:in `open_uri' > from /usr/local/lib/ruby/1.8/open-uri.rb:528:in `open' > from /usr/local/lib/ruby/1.8/open-uri.rb:30:in `open' > from (irb):5 > irb(main):006:0> > > And :read_timeout isn't a known option. > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > > ------=_Part_57853_28341023.1182014332176--