【发布时间】:2021-02-18 01:05:59
【问题描述】:
使用 gem,但它在旧版本上抛出错误
private method `open' called for URI:Module
提取的源代码(在 #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}"
我在 Ruby ruby 2.3.8p459 上运行 Rails 4.2.6
我在这里的深度不够:(
这是在 gem 中调用错误的代码 我用上面的注释解压并重建,因为找不到文档 bth URI::open( 和 URI.open 抛出相同的错误,调用了私有方法。
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
我知道这与我正在运行的 Rails / Ruby 版本有关,但不知道在哪里查看或要问的问题术语。
【问题讨论】:
-
奇怪的是documented method。
-
谢谢不知道如何搜索或文档保存在哪里:)
-
我的意思是它被记录为公开的,但如果不是,那就奇怪了。
标签: ruby-on-rails ruby uri