简体   繁体   中英

private method `open' called for URI:Module ERROR

Working with a gem but its throwing an error on an older build

private method `open' called for URI:Module

Extracted source (around line #135): 133 134 135 136 137 138

  url = construct_url(path)
  #URI::open(url, read_timeout: 600).read
  URI.open(url, read_timeout: 600).read
rescue OpenURI::HTTPError => e
  if error = JSON.load(e.io.read)["error"]
    puts "server returns error for url: #{url}"

I'm running Rails 4.2.6 on Ruby ruby 2.3.8p459

Im a LOT out of my depth here:(

this is the code that calls the error in the gem I unpacked and rebuilt with the comment out above as can't find documentation bth URI::open( and URI.open throw same error, private method called.

                require 'google_search_results' 
            require 'open-uri'
    
            params = {
              q: @q,
              location: "United Kingdom",
              hl: "en",
              gl: "uk",
              google_domain: "google.co.uk",
              api_key: ENV["google_search_api_key"],
              num: 20
            }
    
            search = GoogleSearch.new(params)
            @hash_results = search.get_hash

I know its to do with the version of Rails / Ruby Im running but don't know where to look or terminology of question to ask.

You can use the method like that from ruby 2.4 onwards , but for 2.3 you should just use it as:

open(url, read_timeout: 600).read

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM