Restclient throwing unusual exception - ruby

While trying to use the following gems:
require 'nokogiri'
require 'restclient'
require 'mechanize'
I'm getting the following error:
C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- ffi_c (LoadError)
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/ffi-1.9.10-x86-mingw32/lib/ffi.rb:6:in `rescue in <top (required)>'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/ffi-1.9.10-x86-mingw32/lib/ffi.rb:3:in `<top (required)>'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/windows/root_certs.rb:2:in `<top (required)>'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/windows.rb:7:in `require_relative'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/windows.rb:7:in `<top (required)>'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from C:/Ruby23/lib/ruby/gems/2.3.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient.rb:16:in `<top (required)>'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `require'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `rescue in require'
from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from parse_docs.rb:5:in `<main>'
Since the last thing on this list is line 5, which is require 'restclient' I'm guessing it has something to do with that? However I've attempted to do the following:
Since restclient is deprecated and has moved to rest-client, I tried using rest-client however that doesn't work and produces the same error.
I've also attempted to require 'rubygems' but that when I run the program, it will not allow me to continue and produces the same error.
So I completely took out restclient, this is how I got the idea that restclient is causing the problem , because without it there, the program can run successfully.
So I though what would happen if I rolled back on ffi? So I installed the ffi version that is needed to run restclient However, that didn't help either.
Updated all my gems, still throwing the same error..
Downloaded the latest version on ffi, nothing changes, except now I havea new version of ffi on my system, that's still throwing an error when being used with restclient
Why is restclient producing the ffi error, I've never had this happen to me before. Is rest-client deprecated? Or is there a simple solution that I'm not catching onto? I've researched this, and nobody has had this problem (while using restclient) however there is a ton of people who have gotten this error while using other gems. For example see also here. It might also be worth mentioning that I'm running Windows 7.

The error comes after the ffi tries to load its C extension. If we have a look at the source code of the FFI gem, it tries to load the compiles extension according to the version of Ruby currently running:
begin
require RUBY_VERSION.split('.')[0, 2].join('.') + '/ffi_c'
rescue Exception
require 'ffi_c'
end
The first part fails so it falls back to the require 'ffi_c' which also fails. The problem now is that the first part should not fail.
In your case, it seems you are using a FFI gem which was compiled for another version of Ruby. Unfortunately, ruby has changes its ABI during releases so this doesn't work.
Thus, you need to make sure you are either using the pre-compiled gem matching your ruby version (which might be hard to find) or compiling it yourself. For that, please install the Development Kit for your Ruby version (towards the bottom left of the page). Then, you can install the ffi gem and force it to compile the C-extension on installation:
gem install ffi --platform=ruby
This is required as gem install ffi (without the --platform parameter), rubygems first tries to install the gem variant specific to your platform, i.e. mingw32 in your case, which is available in pre-compiled from from rubygems.org. Unfortunately, this precompiled gem apparently is incompatible with your version of Ruby. As such, you can force rubygems to get the source-version of the gem and compile the C-extension on its own. This is what you are instructing rubygems to do with the --platform=ruby argument.
This matches the description in the issues on FFI's issue tracker.

So I found an answer to this, it had to do with Holger Just's answer with a minor tweak, I'm pretty sure my case is pretty unique because my company likes to hide behind a VPN script. So here's how I did it:
First I needed to install the pre-release gem of ffi using the platform flag: gem install ffi --pre --platform=ruby
Next I had to update the gem: gem update --all (I think that's the correct syntax for the flag)
That got ffi working.

Related

How do I fix psych module not being found or being the right version Ruby

I get the following error when trying to do anything with Ruby, specifically ruby gems:
/usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/2.4.0/yaml.rb:5:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
/usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:130:in `require': incompatible library version - /usr/local/rvm/gems/ruby-2.4.5/gems/psych-3.1.0/lib/psych.so (LoadError)
from /usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
from /usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:34:in `require'
from /usr/local/rvm/gems/ruby-2.4.5/gems/psych-3.1.0/lib/psych.rb:16:in `rescue in <top (required)>'
from /usr/local/rvm/gems/ruby-2.4.5/gems/psych-3.1.0/lib/psych.rb:13:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/2.4.0/yaml.rb:6:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/rubygems.rb:729:in `load_yaml'
from /usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/rubygems/config_file.rb:349:in `load_file'
from /usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/rubygems/config_file.rb:202:in `initialize'
from /usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/rubygems/gem_runner.rb:79:in `new'
from /usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/rubygems/gem_runner.rb:79:in `do_configuration'
from /usr/local/rvm/rubies/ruby-2.4.5/lib/ruby/site_ruby/2.4.0/rubygems/gem_runner.rb:44:in `run'
from /usr/local/rvm/rubies/ruby-2.4.5/bin/gem:21:in `<main>'
I believe the line of note is this one:
LoadError: incompatible library version - /usr/local/rvm/gems/ruby-2.4.5/gems/psych-3.1.0/lib/psych.so
I get this from gem install puppet, gem update, etc. I tried uninstalling and reinstalling libyaml, and same with Ruby. The error happened after I did bundle uninstall puppet to get it to stop pointing to the 6.3.0 gem and point to the 4.10.2 executable. I need Ruby to be able to use Rspec to test the modules. Does anyone know how I can fix this?
Without steps to reproduce the broken system it is hard to say what happened, but I can say in general how you can set this up correctly to use a specific version of Puppet.
Does this help? In the worst case, you can probably uninstall RVM and reinstall it.
Before I continue, let me note that Puppet 4.10.2 and 4.10.3 have both been removed from Rubygems. (Although I was able to install it with PDK.)
For the remainder I assume 4.10.4 instead (just to distinguish it from latest 4.10).
The recommended approach is to use Puppet Development Kit (pdk). If you download and install PDK, you probably just need to do these steps:
pdk convert
rm Gemfile.lock
PUPPET_GEM_VERSION=4.10.4 bundle update # If that version isn't already in PDK.
pdk test unit --puppet-version 4.10.4
If you don't want to go down the PDK path, you can try these alternatives:
Hardcode the version of Puppet you want in Gemfile.
gem 'puppet', '4.10.4'
Or:
gem 'puppet', '~> 4.10' # latest 4.10
Then update your bundle:
rm -f Gemfile.lock
bundle update
Or, you can implement the PUPPET_GEM_VERSION feature by adding this code (this is what I do, for what it's worth):
if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion
else
gem 'puppet'
end
And then:
rm -f Gemfile.lock
PUPPET_GEM_VERSION='~> 4.10' bundle update
Now you can run your unit tests against a specific version of Puppet per normal:
bundle exec rake spec
Or however you set it up.

How can I fix charlock_holmes gem so it works on opensuse Tumbleweed?

I can install charlock_holmes gem on opensuse, trying to open it up in irb quickly, I get this:
> irb
2.3.0 :001 > require 'charlock_holmes'
LoadError: /home/wpostma/.rvm/gems/ruby-2.3.0/gems/charlock_holmes-0.7.3/lib/charlock_holmes/charlock_holmes.so:
undefined symbol: _ZTIN6icu_538ByteSinkE - /home/wpostma/.rvm/gems/ruby-2.3.0/gems/charlock_holmes-0.7.3/lib/charlock_holmes/charlock_holmes.so
from /home/wpostma/.rvm/rubies/ruby-2.3.0/lib64/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/wpostma/.rvm/rubies/ruby-2.3.0/lib64/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/wpostma/.rvm/gems/ruby-2.3.0/gems/charlock_holmes-0.7.3/lib/charlock_holmes.rb:1:in `<top (required)>'
from /home/wpostma/.rvm/rubies/ruby-2.3.0/lib64/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
from /home/wpostma/.rvm/rubies/ruby-2.3.0/lib64/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
from /home/wpostma/.rvm/rubies/ruby-2.3.0/lib64/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from (irb):1
from /home/wpostma/.rvm/rubies/ruby-2.3.0/bin/irb:11:in `<main>'
2.3.0 :002 >
It looks to me like maybe something in charlock_holmes is incompatible with the libicu version inside tumbleweed.
I'm using ruby installed with rvm, and purging all my gemsets and reinstalling does not fix it. Any other ways to get charlock_holmes to work? Maybe I need to install a special copy of libicu (earlier, older) and point the gem at it?
Either of these works. For me the bundle config option works better.
This is a direct command to install the gem, directing it towards the correct libicu version:
gem install charlock_holmes -- --with-icu-dir=/usr/local
This is a command to tell which ever ruby project I install later on this system, will get gems installed by bundler to just work instead of breaking:
bundle config build.charlock_holmes "--with-icu-dir=/usr/local" --global
Since I'm using rvm the above bundle configuration seems to be "global" to that rvm environment only.
In my case, the bundle config is helpful as a large series of actions that would have otherwise failed (installing gems, and bootstrapping a large rails application) just worked.

Unable to activate wordnet - require 'wordnet' fails

I am writing a Ruby script, and I would like to use wordNet to stem String. I want to give it a string that may contain words of the same form and get back the string but after stemming it. I came across Ruby-WordNet and installed wordnet gem and wordnet-defaultdb gem. I also installed Sequel since it is required.
However, I am not sure how to deal with it. When I typed in the script:
require 'rubygems'
require 'sequel'
require 'wordnet'
I get the following error:
/Users/arwa/.rvm/rubies/ruby- 2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:2112:in `raise_if_conflicts': Unable to activate wordnet-1.0.0, because sequel-4.24.0 conflicts with sequel (~> 3.38) (Gem::ConflictError)
from /Users/arwa/.rvm/rubies/ruby- 2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:1280:in `activate'
from /Users/arwa/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems.rb:198:in `rescue in try_activate'
from /Users/arwa/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems.rb:195:in `try_activate'
from /Users/arwa/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:126:in `rescue in require'
from /Users/arwa/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from ./test.rb:5:in `<main>'
If I removed
require 'sequel'
I get the following error:
/Users/arwa/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require': cannot load such file -- sequel (LoadError)
from /Users/arwa/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
from /Users/arwa/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from /Users/arwa/.rvm/gems/ruby-2.2.1/gems/wordnet-1.0.0/lib/wordnet.rb:5:in `<top (required)>'
from /Users/arwa/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
from /Users/arwa/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
from /Users/arwa/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from ./test.rb:4:in `<main>'
I am not sure what is the problem and how to deal with it.
Does any one have any idea on how it works?
Also, if someone can direct me to a place where I can find example on how to code it and to deal with it.
Many thanks in advance.
The error says you have a version conflict.
See what gem list sequel --all says. Odds are good you loaded only the latest version of Sequel by using gem install sequel without specifying the version, or that you have two versions, the one specified by WordNet and the latest
Try removing/uninstalling all Sequel versions installed and reinstall only the specific version:
gem install sequel -v3.38
You can also try modifying the gem requirements for WordNet to not require a specific version of Sequel. Sequel is extremely stable so that should be a safe move.
You have conflicting gem versions installed:
require 'rubygems'
gem 'sequel', '3.48'
require 'sequel'
require 'wordnet'
Will solve your issue.
You can help yourself with a Gemfile. Run bundle init to create one. Run gem install bundler if you have no bundler.
Gemfile:
source "https://rubygems.org"
gem 'sequel'
gem 'wordnet'
Run bundle after you saved your Gemfile. Check Gemfile.lock for the solution.

Ruby gamebox can't find the file gosu.for_1_9.so even though it's right there

Preface: I'm on a Windows 8 box, running Ruby 2.0.0.
I recently installed the gamebox gem for Ruby. During the installation of all its dependencies, a few files, among them the file $RUBYHOME/lib/ruby/gems/2.0.0/gems/gosu-0.7.50-x86-mingw32/lib/gosu.for_1_9.so, did not build properly because of some ASCII/Unicode issues in rdoc, and were thus "skipped". I hadn't payed much attention to it initially, but when I tried to run gamebox test_game to setup a new gamebox game, it spat the following message at me:
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:118:in `require': 126: The specified module could not be found. - C:/Ruby200/lib/ruby/gems/2.0.0/gems/gosu-0.7.50-x86-mingw32/lib/gosu.for_1_9.so (LoadError)
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:118:in `rescue in require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:124:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/gosu-0.7.50-x86-mingw32/lib/gosu.rb:11:in `<top (required)>'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:114:in `require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:114:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/gamebox-0.5.0/lib/gamebox.rb:5:in `<top (required)>'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:66:in `require'
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:66:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/gamebox-0.5.0/bin/gamebox:4:in `<top (required)>'
from C:/Ruby200/bin/gamebox:23:in `load'
from C:/Ruby200/bin/gamebox:23:in `<main>'
The important bit there is The specified module could not be found. - C:/Ruby200/lib/ruby/gems/2.0.0/gems/gosu-0.7.50-x86-mingw32/lib/gosu.for_1_9.so
I then went back and realized the whole Unicode thing, updated rdoc to the newest version as per this guy, and ran gem uninstall gosu followed by gem install gosu. Everything seemed to build just fine, and I saw that the needed file, .../gosu.for_1_9.so, was right where it needed to be.
However, I am still getting exactly the same error about not being able to find gosu.for_1_9.so!
I've been able to find exactly two Google results where someone else had this issue. In one situation the problem was peripheral because the guy was hacking on his gosu installation a bit; in the other, the solution was "Ruby 2 is bad and you should use Ruby 1.9", which is really not my preferred option.
Any ideas?
Ken,
The file is being found, but is not compatible to load in Ruby 2.0.0.
This is a bug / missing feature of Gosu. It does not work with Ruby 2.0.0 on Windows. The author of the gem has plans to work this out, but has not yet tackled it. You can follow up on the issue on Github here: https://github.com/jlnr/gosu/issues/163
The author can be found on freenode IRC in #gosu. I'm sure they could use some help with their windows support. Unfortunately, the answer to using Gamebox on Windows is to downgrade to Ruby 1.9.3. I will add this to the Gamebox wiki.
I agree with #Shawn42
But probably the best way is to install beforehand a ruby version manager.
RVM with Pik is what I use on Windows.
That way you can install the older 1.9.3 version of ruby and call pik to use that version whenever you want to use gamebox. You'll still have ruby 2.0.0 installed and ready to be used for your other projects.
http://www.ruby-on-rails-outsourcing.com/articles/2010/07/28/ruby-version-manager-for-windows/
Cheers

Error while running irb file

This is my first program :
require 'rubygems'
require 'watir'
ie = Watir::IE.new
ie.goto("http://www.google.com")
ie.text_field(:name, "question").set("microsoft")
ie.button(:name, "btnG").click
When I run it,I get the following error, could you please help. I have installed watir-webdriver before running this
C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- watir (LoadError)
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from C:/Ruby200/lib/ruby/site_ruby/2.0.0/rubygems/FirstSample:2:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
Process finished with exit code 1
My guess is that the problem is caused by the fact that you have installed watir-webdriver gem but you are requiring watir gem.
Either install watir gem or require watir-webdriver gem in your code.
I've just replied to your other question with a sample project and instructions regarding DevKit installation.
Note that RubyMine needs a valid Gemfile to manage dependencies. All the gems that you are using should be specified in that file. bundle install should install the dependencies without errors.
If you have errors installing gems, post it as a separate question with more details, but before doing it verify that DevKit was installed properly and can build/run the sample gem from the installation guide.
Some gems may be not fully compatible with the recently released Ruby 2.0 version. If you have no luck getting it to work, try Ruby 1.9.3 instead.

Resources