Twilio app; twilio-ruby(3.4.2),SSL错误

Jay*_*dse 1 ruby twilio

我已经按照Twilio github页面上的示例代码进行操作,但它不起作用.在我的Rails控制台中,它看起来像这样:

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>
Run Code Online (Sandbox Code Playgroud)

还有什么办法可以让twilio-ruby成功发送短信?我已将这些号码和凭据用于来电,因此它们很好.

**编辑2011年12月24日*** 我没有在我的电脑上运行此代码,而是将其部署到heroku.com.然后我没有SSL错误,我能够拨打电话.我很困惑.

amb*_*amb 5

这应该是从3.5.0开始的twilio-ruby版本中的问题.它现在开箱即可"正常工作".

对于3.5.0之前的twilio-ruby版本,没有与gem一起打包的SSL CA证书捆绑包.所以"修复"这个问题的唯一方法是在初始化时将客户端指向一个证书包:

client = Twilio::REST::Client.new sid, token, :ssl_ca_file => '/path/to/file'
Run Code Online (Sandbox Code Playgroud)

或者完全禁用SSL验证(不建议在生产中使用):

client = Twilio::REST::Client.new sid, token, :ssl_verify_peer => false
Run Code Online (Sandbox Code Playgroud)