ruby – 使用youtube上传视频到youtube Data API:Broken pipe(Errno :: EPIPE)

我正在尝试使用youtube data api将本地视频文件上传到我的YouTube帐户.

示例:https://github.com/youtube/api-samples/blob/master/ruby/upload_video.rb

呼叫:

$ruby upload_video.rb --file video.mp4

我收到一条错误消息:

/Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/openssl/buffering.rb:326:in `syswrite': Broken pipe (Errno::EPIPE)
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/openssl/buffering.rb:326:in `do_write'
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/openssl/buffering.rb:344:in `write'
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/http/generic_request.rb:202:in `copy_stream'
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/http/generic_request.rb:202:in `send_request_with_body_stream'
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/http/generic_request.rb:132:in `exec'
...
from upload_video.rb:73:in `main'
from upload_video.rb:91:in `<main>'

upload_video.rb(第73行):

videos_insert_response = client.execute!(
  :api_method => youtube.videos.insert,:body_object => body,:media => Google::APIClient::UploadIO.new(opts[:file],'video/*'),:parameters => {
    :uploadType => 'resumable',:part => body.keys.join(',')
  }
)

解决方法

google-api-client使用faraday gem,默认的http适配器是Net :: HTTP.它似乎无法正常工作.因此我们需要将其切换为其他内容.我将其更改为httpclient,现在工作正常.
只需在您的whatever.rb文件的开头某处添加此行(在需要google的库之后):

Faraday.default_adapter = :httpclient

可以在此处找到支持的http适配器的完整列表:https://github.com/lostisland/faraday#faraday

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...