1

我正在尝试制作一个小红宝石脚本来上传我自己的视频这是完整的代码,它很短:

    require 'openssl'
    OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE # warning: already initialized constant VERIFY_PEER \n 0 
    require 'youtube_it'
    require 'rest-client'

    # Authentication
    auth_devkey      = '...'
    auth_user        = '...'
    auth_pass        = '...'

    # Getting auth token
    response    = RestClient.post "https://www.google.com/accounts/ClientLogin", {:Email => auth_user, :Passwd => auth_pass, :service => "youtube", :source => "..."}, :content_type => 'application/x-www-form-urlencoded'
    auth_token  = response[/(?<=auth=).*/i]
    # so far so good

    # creating a new youtube_it client
    yt_client   = YouTubeIt::Client.new(:username => auth_user, :password =>  auth_pass, :dev_key => auth_devkey)
    # A-Okay


    # Uploading video
    vpath       = "c:/downloads/videos/video.mov"
    upload_response = yt_client.video_upload(File.open(vpath), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :list => 'denied')

    # big error here
    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:677:in `connect'
            from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:677: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:1160:in `request'
            from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.1/lib/restclient/net_http_ext.rb:17:in `request'
            from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:970:in `post'
            from C:/Ruby192/lib/ruby/gems/1.9.1/gems/youtube_it-1.4.1/lib/youtube_it/request/video_upload.rb:525:in `auth_token'
            from C:/Ruby192/lib/ruby/gems/1.9.1/gems/youtube_it-1.4.1/lib/youtube_it/request/video_upload.rb:463:in `authorization_hea
    ders'
            from C:/Ruby192/lib/ruby/gems/1.9.1/gems/youtube_it-1.4.1/lib/youtube_it/request/video_upload.rb:94:in `upload'
            from C:/Ruby192/lib/ruby/gems/1.9.1/gems/youtube_it-1.4.1/lib/youtube_it/client.rb:99:in `video_upload'
            from (irb):81
            from C:/Ruby192/bin/irb:12:in `<main>'

我确定我是否可以立即提供任何其他信息,我可能会错过在这里粘贴,这是解决这个问题所必需的。我不想在这里随便问问题而不用谷歌搜索至少 4 小时,但我找不到任何有用的东西。

谢谢十亿!

4

2 回答 2

1

大家好,这个错误已在 youtube_it 的最新版本中修复,您可以在此处查看

https://github.com/kylejginavan/youtube_it/commit/032f2800ae4c4ab9f6000b23150e3a8d3517815f

问候!

于 2011-10-03T21:16:05.300 回答
1

问题是你不能这样做:

   OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE 

您必须修改 SSLContext 实例的 :verify_mode 属性。您可以尝试通过 rest-client 中的 instance_variable_get 获取 NET::HTTP 对象的实例变量,然后相应地设置 :verify_mode 。

更好的方法是直接设置 rest-client 本身的 :verify_ssl 属性:

RestClient::Request.execute(:method => :post, :url => 'http://example.com', :verify_ssl => OpenSSL::SSL::VERIFY_NONE )

为了进一步阅读,我建议在这里查看源代码

于 2011-03-30T11:56:17.570 回答