4

I've created a gem called kmdata that has an executable. When running bundle exec kmdata decot.7 from within my gem's folder everything works fine. After releasing the gem to rubygems I ran gem install kmdata (in a new window). I then tried to run kmdata decot.7 and I get the following

/Users/kyledecot/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:891:in `connect': undefined method `set_params' for #<OpenSSL::SSL::SSLContext:0x007fff31d59d18> (NoMethodError)
    from /Users/kyledecot/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
    from /Users/kyledecot/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:851:in `start'
    from /Users/kyledecot/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:1367:in `request'
    from /Users/kyledecot/.rvm/gems/ruby-2.0.0-p247/gems/kmdata-0.0.3/lib/kmdata.rb:24:in `get'
    from /Users/kyledecot/.rvm/gems/ruby-2.0.0-p247/gems/kmdata-0.0.3/bin/kmdata:5:in `<top (required)>'
    from /Users/kyledecot/.rvm/gems/ruby-2.0.0-p247/bin/kmdata:23:in `load'
    from /Users/kyledecot/.rvm/gems/ruby-2.0.0-p247/bin/kmdata:23:in `<main>'

The line in lib/kmdata.rb is

response = http.request(Net::HTTP::Get.new(path))

Update #1

This only appears to be an issue when using 2.0. If I run the same command in 1.9.3 then everything works as expected.

Kyle Decot
  • 20,715
  • 39
  • 142
  • 263

3 Answers3

4

You likely need to include this line (e.g., at the beginning of your file):

require 'openssl'

I had this error on 2.0, and adding this line fixed it. Maybe your 1.9.3 has some configuration/gem that implicitly requires that?

chesterbr
  • 2,940
  • 3
  • 29
  • 26
  • 1
    This actually fixes sporadic occurences of that error in plain net/http usage as well. (Saying so here because this is the first hit for the error message.) – Andreas Krey Sep 12 '19 at 07:48
0

Just out of the blue, but have you configured Net::HTTP to use an SSL connection? Using Net::HTTP.get for an https url

Here's another person having the same problem...no mention that it's a solution, but try it out: https://www.ruby-forum.com/topic/4417738

This looks like an error in Net::HTTP...are you using the most recent version of the gem?

Community
  • 1
  • 1
0

If I were you, I would focus on:

undefined method `set_params' for #<OpenSSL::SSL::SSLContext:0x007fff31d59d18> (NoMethodError)

I think you could have your gems organized in such a way that there's either something not being included, or you have two classes or methods with the same name, and the wrong one is now being chosen. I've had something like this happen a couple of times.

Simply put, it's probably going to end up being a scope thing - a require / include, or a duplicate method.

If I'm right, there's not much we can do to help - without access to your computer.

I hope you find it. I would recommend doing some grepping/searching through files for method names, class names etc. if you haven't already.

Edit: looking back, it seems like you're just dealing with stock code. If that's the case, try uninstalling all versions of ruby, and then re-installing 2.0.0. You'd be surprised - I've had 1.9.3 do something like this when they are both installed.

Plasmarob
  • 1,321
  • 12
  • 20