无法使用所需的 tumblr_client 运行 ruby 脚本
Posted
技术标签:
【中文标题】无法使用所需的 tumblr_client 运行 ruby 脚本【英文标题】:Can't run ruby script with required tumblr_client 【发布时间】:2022-01-23 22:42:07 【问题描述】:。已安装 gem 'tumblr_client',但出现错误:
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-0.9.2/lib/faraday/options.rb:153:in `new': tried to create Proc object without a block (ArgumentError)
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-0.9.2/lib/faraday/options.rb:153:in `memoized'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-0.9.2/lib/faraday/options.rb:234:in `<class:ProxyOptions>'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-0.9.2/lib/faraday/options.rb:216:in `<module:Faraday>'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-0.9.2/lib/faraday/options.rb:1:in `<top (required)>'
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:148:in `require'
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:148:in `require'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-0.9.2/lib/faraday.rb:80:in `block in require_libs'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-0.9.2/lib/faraday.rb:79:in `each'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-0.9.2/lib/faraday.rb:79:in `require_libs'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-0.9.2/lib/faraday.rb:240:in `<module:Faraday>'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-0.9.2/lib/faraday.rb:16:in `<top (required)>'
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/tumblr_client-0.8.5/lib/tumblr/connection.rb:1:in `<top (required)>'
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/tumblr_client-0.8.5/lib/tumblr/client.rb:4:in `<top (required)>'
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/tumblr_client-0.8.5/lib/tumblr_client.rb:1:in `<top (required)>'
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `require'
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
from 1.rb:2:in `<main>'
<internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- tumblr_client (LoadError)
from <internal:C:/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from 1.rb:2:in `<main>'
脚本源代码:
require 'tumblr_client'
require 'json'
client = Tumblr::Client.new(
:consumer_key => 'bla-bla',
:consumer_secret => 'bla-bla',
:oauth_token => 'bla-bla',
:oauth_token_secret => 'bla-bla'
)
res = client.queue("dystopia-arts-girls.tumblr.com", :limit => 20, :offset => 0)
File.open('result.json', 'w') |file| file.write res.to_json
【问题讨论】:
看起来你还没有运行gem install tumblr_client
。它告诉您在 require
语句中找不到 gem。
我运行gem install tumblr_client
。真的。我什至尝试将它放在带有脚本的文件夹中,并将 gem 中的所有路径重写为相对路径。它不想工作
你有多个 ruby 安装吗?您确定为您尝试运行它的 ruby 安装了 gem?
是的,我检查了那个,它甚至看到了宝石。但是为什么会碰到tumblr_client-0.8.5/lib/tumblr/connection.rb
我不知道
“法拉第”有问题。我会尝试更新它
【参考方案1】:
问题出在“faraday”和“tumblr_client”的版本上 我是如何修复它的:
> gem install specific_install
> gem specific_install https://github.com/tumblr/tumblr_client
我还卸载了旧版本的 faraday
和 faraday_middleware
【讨论】:
以上是关于无法使用所需的 tumblr_client 运行 ruby 脚本的主要内容,如果未能解决你的问题,请参考以下文章