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

时间:2017-01-29 15:56:23

标签: ruby null timezone rufus-scheduler argument-error

我用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

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

2 个答案:

答案 0 :(得分:1)

在调度程序实例化之前明确设置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

答案 1 :(得分:0)

这是所有的代码吗? 我跑了它,它对我来说很好。

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行。也许更多的信息可以帮助......