0

I'm following the Jumpstart Labs MicroBlogger tutorial and I'm running into an issue where I'm unable to connect to twitter. I am getting the following errors:

C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:799:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (Twitter::Error::ClientError)
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:799:in `block in connect'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:799:in `connect'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:744:in `start'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:1284:in `request'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/adapter/net_http.rb:75:in `perform_request'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/adapter/net_http.rb:38:in `call'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/response.rb:8:in `call'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/response.rb:8:in `call'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/response.rb:8:in `call'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/request/url_encoded.rb:14:in `call'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/request/multipart.rb:13:in `call'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/twitter-4.8.1/lib/twitter/request/multipart_with_file.rb:14:in `call'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/connection.rb:253:in `run_request'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/faraday-0.8.8/lib/faraday/connection.rb:118:in `post'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/twitter-4.8.1/lib/twitter/client.rb:108:in `request'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/twitter-4.8.1/lib/twitter/client.rb:72:in `post'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/twitter-4.8.1/lib/twitter/api/utils.rb:82:in `object_from_response'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/twitter-4.8.1/lib/twitter/api/tweets.rb:129:in `update'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/jumpstart_auth-0.3.0/lib/jumpstart_auth.rb:32:in `update'
    from C:/Users/Steve/RubymineProjects/MicroBlogger/micro_blogger.rb:12:in `tweet'
    from C:/Users/Steve/RubymineProjects/MicroBlogger/micro_blogger.rb:18:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

This is my code so far:

require 'jumpstart_auth'

class MicroBlogger
  attr_reader :client

  def initialize
    puts "Initializing"
    @client = JumpstartAuth.twitter
  end

  def tweet(message)
    @client.update(message)
  end

end

blogger = MicroBlogger.new
blogger.tweet("hey")
Ash Wilson
  • 22,820
  • 3
  • 34
  • 45
stytown
  • 1,642
  • 2
  • 16
  • 22

2 Answers2

1

As indicated in the error message, the SSL library couldn't verify the SSL certificate returned from the Twitter server. In this case, it is most likely because no certificate authorities were installed for you.

The details and solution are available here:

https://gist.github.com/fnichol/867550#file-readme-md

I suggest using the "boring" method, since it does not involve running code copied off the internet (instructions in case the link disappears, but better to read info at link):

  • Download http://curl.haxx.se/ca/cacert.pem
  • Save it to somewhere like C:\RailsInstaller\cacert.pem
  • Run set SSL_CERT_FILE=C:\RailsInstaller\cacert.pem to set the location for the current shell
  • Run your script in the same shell
Justin
  • 1,561
  • 10
  • 12
  • Thanks Justin, after reading your comment, I tried it out (I also found this: http://stackoverflow.com/questions/5720484/how-to-solve-certificate-verify-failed-on-windows the second question). I've tried restarting after I followed the steps, but I'm still receiving the same error. Thank you for your suggestions. – stytown Nov 04 '13 at 06:16
  • Restarted what the script? Your computer? Setting SSL_CERT_FILE only works for your current shell. Did you try the instructions at https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/environment_variables.mspx?mfr=true to set the environment variable more permanently? Are you running your program from inside RubyMine? – Justin Nov 04 '13 at 06:26
  • This is what I did: Download http://curl.haxx.se/ca/cacert.pem into c:\railsinstaller\cacert.pem Go to your Computer -> Advanced Settings -> Environment Variables Create a new System Variable: Variable: SSL_CERT_FILE Value: C:\RailsInstaller\cacert.pem – stytown Nov 04 '13 at 06:30
  • And, yes, I am running the program from inside RubyMine – stytown Nov 04 '13 at 06:31
  • 1
    I think RubyMine might be getting in your way here, depending on how it runs your script (I have no idea). Try opening up the command line with Ruby (I assume that's in your menu somewhere?). Check the variable is set right: `echo %SSL_CERT_FILE%`. Then run your script with Ruby (from `C:/Users/Steve/RubymineProjects/MicroBlogger/micro_blogger.rb` of course): `ruby micro_blogger.rb` – Justin Nov 04 '13 at 06:42
  • Ah, you were right! For some reason it does work if I run it from the Ruby command line. Very odd. Now, if only I could figure out how to run it from RubyMine. Thank you Justin. – stytown Nov 04 '13 at 06:49
0

If you have installed ruby directly to windows you can copy the cacert.pem file to the Ruby200dir(eg. c:\ruby200) and run the set SSL_CERT_FILE=[path to the cert file] command from the command prompt.

Keep in mind that this will require you to add the SSL cert for every boot of your computer

Adrian Badarau
  • 143
  • 1
  • 6