Jumpstart Labs MicroBlogger无法连接

时间:2013-11-04 02:36:29

标签: ruby twitter twitter-oauth

我正在关注Jumpstart Labs MicroBlogger tutorial,我遇到了一个我无法连接到Twitter的问题。我收到以下错误:

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>'

到目前为止,这是我的代码:

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

2 个答案:

答案 0 :(得分:1)

如错误消息所示,SSL库无法验证从Twitter服务器返回的SSL证书。在这种情况下,很可能是因为没有为您安装证书颁发机构。

详情和解决方案可在此处获取:

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

我建议使用“无聊”方法,因为它不涉及运行从互联网上复制的代码(如果链接消失,但更好地在链接上阅读信息时的说明):

  • 下载http://curl.haxx.se/ca/cacert.pem
  • 将其保存到C:\RailsInstaller\cacert.pem
  • 之类的地方
  • 运行set SSL_CERT_FILE=C:\RailsInstaller\cacert.pem以设置当前shell的位置
  • 在同一个shell中运行您的脚本

答案 1 :(得分:0)

如果已将ruby直接安装到Windows,则可以将cacert.pem文件复制到Ruby200dir(例如c:\ ruby​​200)并从命令提示符运行set SSL_CERT_FILE=[path to the cert file]命令。

请记住,这将要求您为计算机的每次启动添加SSL证书