0

基础层面的第一个问题 - Ruby 中未初始化的常量错误是什么意思?我来自 Objective-c 背景,如果这有助于提供一些上下文。

其次,我在 Rails 中运行一个 rake 任务,它抛出了上述错误。具体来说,当我使用“tor-privoxy”gem 时会发生错误,这是一个 Mechanize 包装器,允许通过 tor 代理进行自动浏览。

我正在使用 github 上提供的以下示例代码:https ://github.com/pirj/tor-privoxy

agent ||= TorPrivoxy::Agent.new '127.0.0.1', '', {8118 => 9050} do |agent|
    sleep 10
    puts "New IP is #{agent.ip}"
    page = agent.get('https://www.example.com/')
end
>> New IP is 72.141.125.115
>> NameError: uninitialized constant Net::HTTP::Persistent::SSLReuse::HTTPResponse
    from /Library/Ruby/Gems/1.8/gems/net-http-persistent-2.3.3/lib/net/http/persistent/ssl_reuse.rb:115:in `connect'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:548:in `start'
    from /Library/Ruby/Gems/1.8/gems/net-http-persistent-2.3.3/lib/net/http/persistent.rb:405:in `connection_for'
    from /Library/Ruby/Gems/1.8/gems/net-http-persistent-2.3.3/lib/net/http/persistent.rb:616:in `request'
    from /Library/Ruby/Gems/1.8/gems/mechanize-2.1/lib/mechanize/http/agent.rb:264:in `fetch'
    from /Library/Ruby/Gems/1.8/gems/mechanize-2.1/lib/mechanize.rb:319:in `get'
    from /Library/Ruby/Gems/1.8/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:16:in `send'
    from /Library/Ruby/Gems/1.8/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:16:in `method_missing'
    from (irb):4
    from /Library/Ruby/Gems/1.8/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:11:in `call'
    from /Library/Ruby/Gems/1.8/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:11:in `initialize'
    from (irb):1:in `new'
    from (irb):1

另一方面,如果我在 irb 中运行相同的代码,它不会抛出未初始化的常量错误。我确保我的 gemfile 包含“tor-privoxy”并运行了“bundle install”命令。

4

1 回答 1

1

如果您想在 Mac 上使用 ruby​​,我建议您使用 rvm 或 rbenv 之类的工具来管理您的 ruby​​ 安装。

您遇到的错误似乎是已知的。看看这个 github 问题:https ://github.com/thrillcall/net-http-persistent/commit/9f770b4660f1c9c433c1f3b50ba24dd4f1f71cf8

于 2012-07-18T20:51:05.697 回答