Jumpstart Labs MicroBlogger unable to connect - ruby

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")

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

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

Related

Openshift rhc port forward exception

I am trying to open ports so i access my database remotely from my pc
I am running on Ruby200-x64 and when i try to access port forward
rhc port-forward -a appname
i get the following response/error:
Checking available ports ... C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/pageant.rb:176:in `malloc': bignum too big to convert into `long' (RangeError)
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/pageant.rb:176:in `malloc_ptr'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/pageant.rb:240:in `get_token_information'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/pageant.rb:213:in `get_current_user'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/pageant.rb:189:in `get_security_attributes_for_user'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/pageant.rb:332:in `send_query'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/pageant.rb:309:in `send'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/agent/socket.rb:148:in `send_packet'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/agent/socket.rb:165:in `send_and_wait'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/agent/socket.rb:76:in `negotiate!'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/agent/socket.rb:48:in `connect'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/key_manager.rb:179:in `agent'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/key_manager.rb:103:in `each_identity'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/methods/publickey.rb:19:in `authenticate'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:79:in `block in authenticate'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:66:in `each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:66:in `authenticate'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh.rb:211:in `start'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rhc-1.38.4/lib/rhc/commands/port_forward.rb:86:in `run'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rhc-1.38.4/lib/rhc/commands.rb:294:in `execute'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rhc-1.38.4/lib/rhc/commands.rb:285:in `block (3 levels) in to_commander'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/commander-4.2.1/lib/commander/command.rb:180:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/commander-4.2.1/lib/commander/command.rb:180:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/commander-4.2.1/lib/commander/command.rb:155:in `run'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/commander-4.2.1/lib/commander/runner.rb:421:in `run_active_command'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rhc-1.38.4/lib/rhc/command_runner.rb:72:in `run!'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/commander-4.2.1/lib/commander/delegates.rb:8:in `run!'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rhc-1.38.4/lib/rhc/cli.rb:37:in `start'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rhc-1.38.4/bin/rhc:20:in `<top (required)>'
from C:/Ruby200-x64/bin/rhc:23:in `load'
from C:/Ruby200-x64/bin/rhc:23:in `<main>'
It's a bit late but maybe it can help to newcomer.
The solution is, or better say- workaround, to exit the pageant while you port-forward the app. And when done turn it on again if you need to ssh to it.
I found a sort of workaround too, whenever i recieve this error i do the oldest trick in the books, a restart and it works all the times(for now)

Ruby, Net-SSH: connection closed by remote host

Issue where SSH session gets disconnected after less than 1 sec by remote when using ruby net-ssh. It happens very randomly.
/home/admin/.rvm/gems/ruby-2.1.3/gems/net-ssh-2.9.2/lib/net/ssh/transport/packet_stream.rb:89:in `next_packet': connection closed by remote host (Net::SSH::Disconnect)
from /home/admin/.rvm/gems/ruby-2.1.3/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:183:in `block in poll_message'
from /home/admin/.rvm/gems/ruby-2.1.3/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:178:in `loop'
from /home/admin/.rvm/gems/ruby-2.1.3/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:178:in `poll_message'
from /home/admin/.rvm/gems/ruby-2.1.3/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:461:in `dispatch_incoming_packets'
from /home/admin/.rvm/gems/ruby-2.1.3/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:222:in `preprocess'
from /home/admin/.rvm/gems/ruby-2.1.3/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:206:in `process'
from /home/admin/.rvm/gems/ruby-2.1.3/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:170:in `block in loop'
from /home/admin/.rvm/gems/ruby-2.1.3/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:170:in `loop'
from /home/admin/.rvm/gems/ruby-2.1.3/gems/net-ssh-2.9.2/lib/net/ssh/connection/session.rb:170:in `loop'
from /home/user/ruby/cisco/ssh.rb:43:in `run'
from /home/user/ruby/cisco/base.rb:48:in `run'
from rssh.rb:11:in `<main>'
Already tried specifying timeout settings and encryption algorithms.
Solution at https://github.com/net-ssh/net-ssh/issues/93 does not fix the issue

Ruby Gem Twitter - certificate verify failed (Twitter::Error::ClientError)

I am trying to use the ruby gem 'twitter' but for unknown reasons I cant get it to work.
Here is the .rb code:
require 'twitter'
puts "Greetings, World!"
puts "Checkpoint 1"
Twitter.configure do |config|
config.consumer_key = "xxxxxxx" #removed for posting
config.consumer_secret = "xxxxxxx" #removed for posting
config.oauth_token = "xxxxxxx" #removed for posting
config.oauth_token_secret = "xxxxxxx" #removed for posting
end
Twitter.verify_credentials
puts "Checkpoint 2"
and I get the following error:
Greetings, World!
Checkpoint 1
C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:918:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (Twitter::Error::ClientError)
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:918:in `block in connect'
from C:/Ruby200-x64/lib/ruby/2.0.0/timeout.rb:66:in `timeout'
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:918:in `connect'
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:851:in `start'
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:1367:in `request'
from C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:1126:in `get'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/adapter/net_http.rb:73:in `perform_request'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/adapter/net_http.rb:38:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/response.rb:8:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/response.rb:8:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/response.rb:8:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/request/url_encoded.rb:14:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/request/multipart.rb:13:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/twitter-4.8.0/lib/twitter/request/multipart_with_file.rb:14:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/connection.rb:247:in `run_request'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/faraday-0.8.7/lib/faraday/connection.rb:100:in `get'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/twitter-4.8.0/lib/twitter/client.rb:108:in `request'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/twitter-4.8.0/lib/twitter/client.rb:66:in `get'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/twitter-4.8.0/lib/twitter/api/utils.rb:82:in `object_from_response'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/twitter-4.8.0/lib/twitter/api/users.rb:50:in `verify_credentials'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/twitter-4.8.0/lib/twitter.rb:60:in `method_missing'
from C:/Ruby200-x64/AppCode/twitter_connect.rb:13:in `<main>'
I am a ruby newbie and I cant make sense of the client error... perhaps I am missing something. I have also confirmed my Oauth credentials are working in python.
Thanks in advance and I look forward to your help.
I was able to solve my own question. For those having the same issue try using the following:
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
It disables the SSL security but it allows you to process with troubleshooting. The underlying issue is an outdated SSL.
I'm very new to ruby as well but are you using a Mac? It may be because of outdated SSL certificate files. Here's a link to instructions that solved the problem for me.
http://railsapps.github.io/openssl-certificate-verify-failed.html

With Nokogiri i am getting error "initialize': getaddrinfo: No such host is known. (SocketError)"

I worte the below code, just to start the Nokogiri to mee the requirement and when I ran it for testing got the error:
D:\WIPData\Ruby\Scripts>Nokogiri.rb
C:/Ruby193/lib/ruby/1.9.1/net/http.rb:762:in `initialize': getaddrinfo: No such
host is known. (SocketError)
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:762:in `open'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:762:in `block in connect'
from C:/Ruby193/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
from C:/Ruby193/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:762:in `connect'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:744:in `start'
from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:306:in `open_http'
from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:775:in `buffer_open'
from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:203:in `block in open_loop'
from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:201:in `catch'
from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:201:in `open_loop'
from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:146:in `open_uri'
from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:677:in `open'
from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:33:in `open'
from D:/WIPData/Ruby/Scripts/Nokogiri.rb:6:in `<main>'
D:\WIPData\Ruby\Scripts>
CODE
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML::Document for the page we’re interested in...
doc = Nokogiri::HTML(open('http://www.google.co.in'))
Why so and how to fix the same,please advice me.
It appears you need to configure a proxy. Find out what the proxy URL/Port is for your organization (and whether there needs to be authentication). You may be able to view this information from your browser configuration. In order to use it with your Ruby code, you need to set the HTTP_PROXY environment variable.
You can set it in Ruby code:
ENV['HTTP_PROXY'] = 'http://hostname:port'
or if you need authentication:
ENV['HTTP_PROXY'] = 'http://username:password#hostname:port'
A more permanent solution is to set HTTP_PROXY in your system environment variables.

Twilio app; twilio-ruby (3.4.2), SSL error

I have followed the sample code on the Twilio github page and it doesn't work. In my Rails console, it looks like this:
irb(main):039:0> require 'twilio-ruby'
=> nil
irb(main):040:0* account_sid='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
=> "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
irb(main):041:0> auth_token='yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
=> "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
irb(main):042:0> client=Twilio::REST::Client.new account_sid, auth_token
=> <Twilio::REST::Client #account_sid=AC1322312300a752f6e84a8254535ecce5>
irb(main):043:0> client.account.sms.messages.create :from=>'16135551234', :to=>'16135551212', :body=>"Ada is fat"
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:678:in `connect'
from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:678:in `block in connect'
from C:/Ruby192/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
from C:/Ruby192/lib/ruby/1.9.1/timeout.rb:87:in `timeout'
from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:678:in `connect'
from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:637:in `do_start'
from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:626:in `start'
from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1168:in `request'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/net_http_ext.rb:51:in `request'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/twilio-ruby-3.4.2/lib/twilio-ruby/rest/client.rb:214:in `connect_and_send'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/twilio-ruby-3.4.2/lib/twilio-ruby/rest/client.rb:138:in `block (2 levels) in <class:Client>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/twilio-ruby-3.4.2/lib/twilio-ruby/rest/list_resource.rb:73:in `create'
from (irb):43
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.11/lib/rails/commands/console.rb:44:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.11/lib/rails/commands/console.rb:8:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.11/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'irb(main):044:0>
What else do I need to do to get twilio-ruby to successfully send a text message? I have used these numbers and credentials for incoming calls, so they are good.
** EDIT Dec 24, 2011 ***
Instead of running this code on my PC, I deployed it to heroku.com. Then I had no SSL errors and I was able to place outgoing calls. I'm very puzzled.
This shouldn't be a problem in twilio-ruby versions starting with 3.5.0. It "just works" out of the box now.
With twilio-ruby versions before 3.5.0 there wasn't an SSL CA cert bundle packaged with the gem. So the only way to "fix" this was to either point your client at a cert bundle at initialization time:
client = Twilio::REST::Client.new sid, token, :ssl_ca_file => '/path/to/file'
or to disable SSL verification altogether (not recommended in production):
client = Twilio::REST::Client.new sid, token, :ssl_verify_peer => false
You may be missing root certificate files. This typically shouldn't be necessary but you can try disabling certificate verification by adding these lines before making the call:
require 'open-uri'
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

Resources