1

我遵循了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>

我还需要做什么才能让 twilio-ruby 成功发送短信?我已经将这些号码和凭据用于来电,所以它们很好。

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

4

2 回答 2

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'

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

client = Twilio::REST::Client.new sid, token, :ssl_verify_peer => false
于 2012-01-15T21:33:08.090 回答
1

您可能缺少根证书文件。这通常不是必需的,但您可以尝试通过在拨打电话之前添加以下行来禁用证书验证:

require 'open-uri'
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
于 2011-12-21T05:44:28.580 回答