Search code examples
ruby-on-railsrubyopen-uri

Ruby open_uri error NoMethodError: undefined method `strip' for 10:Fixnum


When I use this everything is fine:

html = open("http://"+self.url).read

But when I add a user agent:

html = open("http://"+self.url, "User-Agent" => "Ruby", 'read_timeout' => 10 ).read

I get:

NoMethodError: undefined method `strip' for 10:Fixnum
    from /Users/a_user/.rbenv/versions/2.2.3/lib/ruby/2.2.0/net/http/header.rb:17:in `block in initialize_http_header'

What is wrong here?


Solution

  • Pass 10 as string not integer value

    html = open("http://"+self.url, "User-Agent" => "Ruby", 'read_timeout' => '10' ).read
    

    OpenURI is trying to run strip on the value