401 unauthorized errors on Heroku with Delayed Job
Okay, I figured this out by - of course - browsing the source of the various libraries that were invoked in the backtrace.
The most relevant line:
vendor/bundle/ruby/1.9.1/gems/heroku-api-0.3.5/lib/heroku/api/processes.rb:9:in `get_ps'
This uses the heroku-api gem to go get some worker processes. Browsing the source of the heroku-api gem, I see that when you make a request via the API, it initializes a connection like so:
@api_key = options.delete(:api_key) || ENV['HEROKU_API_KEY']if !@api_key && options.has_key?(:username) && options.has_key?(:password) @connection = Excon.new("#{options[:scheme]}://#{options[:host]}", options.merge(:headers => HEADERS)) @api_key = self.post_login(options[:username], options[:password]).body["api_key"]end
My environment did not have ENV['HEROKU_API_KEY']
set. I did have the HEROKU_PASSWORD
set, which contains the same data, but that's not what this gem is looking for. Thus, I was getting 401 errors on this.
I will submit an update to the Heroku documentation and ask them to include this as one of the steps, since it is not in there now.
To fix this, I simply did:
heroku config:add HEROKU_API_KEY=KEY
Where KEY is the same as the value for HEROKU_PASSWORD. (You can view all config vars with heroku config
).