Ruby 无法从 nil 确定时区(参数错误)



我用ruby写了一些代码。当我尝试运行代码时出现此错误:

/Users/macbook/.rvm/gems/ruby-2.2.2/gems/rufus-scheduler-3.3.3/lib/rufus/scheduler/zotime.rb:41:
  in `initialize':
  cannot determine timezone from nil (etz:nil,tnz:"+03",tzid:nil) (ArgumentError)

编辑:

我正在使用电子书宝石。我只添加了使用者密钥和访问令牌。我的.rb文件是:

require 'twitter_ebooks'
class MyBot < Ebooks::Bot
  def configure
    self.consumer_key = 'Consumer Key'
    self.consumer_secret = 'Consumer Secret'
    self.blacklist = ['tnietzschequote']
    self.delay_range = 1..6
  end
  def on_startup
    scheduler.every '24h' do
    end
  end
  def on_message(dm)
  end
  def on_follow(user)
  end
  def on_mention(tweet)
  end
  def on_timeline(tweet)
  end
  def on_favorite(user, tweet)
  end
  def on_retweet(tweet)
  end
end
MyBot.new("twitter_id") do |bot|
  bot.access_token = "Access Token" # Token connecting the app to this account
  bot.access_token_secret = "Access Token Secret" 
end

如果有人帮助我,我会很高兴的。

在调度程序实例化之前显式设置ENV['TZ']

ENV['TZ'] = 'Asia/Shanghai' # your time zone 
  # or
ENV['TZ'] = Time.zone.tzinfo.identifier
scheduler = Rufus::Scheduler.new
# ...

应该:)解决您的问题

见 https://github.com/jmettraux/rufus-scheduler#i-get-zotimerb41in-initialize-cannot-determine-timezone-from-nil

这就是全部代码吗?我运行了它,它对我来说效果很好。

mb = MyBot.new("twitter_id") do |bot|
  bot.access_token = "Access Token" # Token connecting the app to this account
  bot.access_token_secret = "Access Token Secret"
end
p mb.access_token
p mb.access_token_secret

这两者都产生了适当的值。

错误表明第 41 行有问题,但您发布的代码不是 41 行。也许更多的信息会有所帮助...

相关内容

  • 没有找到相关文章

最新更新