0

我正在关注Jumpstart Labs MicroBlogger 教程,但遇到了无法连接到 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")
4

2 回答 2

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 中运行你的脚本
于 2013-11-04T05:59:23.317 回答
0

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

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

于 2014-08-12T05:04:01.310 回答