HTTP 401 Fog::Storage::Rackspace::ServiceError - carrierwave

i am working to get with Rails 4 / Ruby 2 fog / carrierwave integration. Basically I have in my app after around a day of the unicorn servers running it is returning: [HTTP 401] Fog::Storage::Rackspace::ServiceError
I then query the server, and check if I can manually hit the server, and have no issues.
So I am very lost and what to do.
F, [2013-06-17T00:47:58.519007 #31200] FATAL -- :
ActionView::Template::Error ([HTTP 401] Fog::Storage::Rackspace::ServiceError):
21: <li class="span4">
22: <div class="thumbnail">
23: <div style="height: 270px">
24: <%= image_tag(website.logo_url(:web), :class => 'img-rounded') if website.logo? %>
25: </div>
Today I saw that they updated FOG to 1.12.1 and am trying to upgrade, but I really don't know what the issue is. It almost seems as though the connection to Rackspace goes bad.... Any thoughts? Thanks!!

Thanks to Henning's observations, I was able to find that Fog's Rackspace CDN service was not re-authenticating after the authentication token expired. I have submitted the following pull request to fog => https://github.com/fog/fog/pull/1899.
I expect a new version of Fog to be released in early July with this fix. In the interim, I have created a patch to be applied to the current Fog gem -> https://gist.github.com/krames/5817816
This file should be saved in the initializer's directory of your rails application and named 01_cdn_patch.rb in order for it to be properly applied. It will only work for Fog 1.12.1.

we ran into the same issue. The AuthToken expires after 24 hours. When this happens fog raises this error and did not try to reauthenticate. If you restart the server Fog reauthenticates. But that's doesn't count as a solution.
Hope you will figure out some solution. I added the relevant stack trace. We use fog 1.12.1.
Cheers
[GEM_ROOT]/gems/excon-0.23.0/lib/excon/middlewares/expects.rb:10:in `'
[GEM_ROOT]/gems/excon-0.23.0/lib/excon/connection.rb:353:in `'
[GEM_ROOT]/gems/excon-0.23.0/lib/excon/connection.rb:247:in `'
[GEM_ROOT]/gems/fog-1.12.1/lib/fog/core/connection.rb:25:in `'
[GEM_ROOT]/gems/fog-1.12.1/lib/fog/rackspace/cdn.rb:157:in `'
[GEM_ROOT]/gems/fog-1.12.1/lib/fog/rackspace/requests/cdn/head_container.rb:30:in `'
[GEM_ROOT]/gems/fog-1.12.1/lib/fog/rackspace/cdn.rb:62:in `'
[GEM_ROOT]/gems/fog-1.12.1/lib/fog/rackspace/models/storage/directory.rb:183:in `'
[GEM_ROOT]/gems/fog-1.12.1/lib/fog/rackspace/models/storage/directory.rb:131:in `'
[GEM_ROOT]/gems/fog-1.12.1/lib/fog/rackspace/models/storage/file.rb:177:in `'
[GEM_ROOT]/gems/carrierwave-0.8.0/lib/carrierwave/storage/fog.rb:304:in `'
[GEM_ROOT]/gems/carrierwave-0.8.0/lib/carrierwave/storage/fog.rb:322:in `'
[GEM_ROOT]/gems/carrierwave-0.8.0/lib/carrierwave/uploader/url.rb:19:in `'
[GEM_ROOT]/gems/carrierwave-0.8.0/lib/carrierwave/uploader/versions.rb:160:in `'
[GEM_ROOT]/gems/carrierwave-0.8.0/lib/carrierwave/uploader/default_url.rb:8:in `'
[GEM_ROOT]/gems/carrierwave-0.8.0/lib/carrierwave/uploader/versions.rb:156:in `'
[GEM_ROOT]/gems/carrierwave-0.8.0/lib/carrierwave/uploader/default_url.rb:8:in `'
[GEM_ROOT]/gems/carrierwave-0.8.0/lib/carrierwave/mount.rb:377:in `'
[GEM_ROOT]/gems/carrierwave-0.8.0/lib/carrierwave/mount.rb:187:in `'

I had the same problem and resolved it using gem "fog", "~> 1.14.0"in the Gemfile rather than gem "fog", "~> 1.10.1" as this page recommends https://github.com/carrierwaveuploader/carrierwave#using-rackspace-cloud-files

I am a member of the developer relations team at Rackspace and I am responsible for working on Fog. Sorry to hear that you are experiencing issues.
Can you share your configuration information with me (obfuscating your username and api key of course). Feel free to share it here or email me at https://developer.rackspace.com/support/
Also, can you tell me what data center your container is in?
Thanks!
Kyle

Related

NoMethodError (undefined method `encode' for JsonWebToken:Module)

I am facing a problem with JWT gem file after I upgrade my rails version from 4.2 to 5.0.
Can anybody please help me.
I am using Rails - 5.0.7.2
Ruby - 2.5.3
JwT - 2.2.1
require 'jwt'
payload = { data: 'test' }
token = JWT.encode payload, nil, 'none'
Traceback (most recent call last):
8: from bin/rails:11:in <main>' 7: from bin/rails:11:in require'
6: from /home/sahu/.rvm/gems/ruby-2.5.3/gems/railties-5.0.7.2/lib/rails/commands.rb:18:in <top (required)>' 5: from /home/sahu/.rvm/gems/ruby-2.5.3/gems/railties-5.0.7.2/lib/rails/commands/commands_tasks.rb:49:in run_command!'
4: from /home/sahu/.rvm/gems/ruby-2.5.3/gems/railties-5.0.7.2/lib/rails/commands/commands_tasks.rb:78:in console' 3: from /home/sahu/.rvm/gems/ruby-2.5.3/gems/railties-5.0.7.2/lib/rails/commands/console_helper.rb:9:in start'
2: from /home/sahu/.rvm/gems/ruby-2.5.3/gems/railties-5.0.7.2/lib/rails/commands/console.rb:65:in start' 1: from (irb):3 NoMethodError (undefined method encode' for JsonWebToken:Module)
I tried by downgrade the Jwt gem version but still facing same issue.
and also getting warnings like below -
/home/sahu/.rvm/gems/ruby-2.5.3/gems/json_web_token-0.3.5/lib/json_web_token.rb:36: warning: already initialized constant JWT
/home/sahu/.rvm/gems/ruby-2.5.3/gems/jwt-2.2.1/lib/jwt/base64.rb:5: warning: previous definition of JWT was here
Finally, I found the problem.
Before upgrading my rails version I have JWT Gem and After I Upgrade my rails version. I added a new gem intuit-oauth. This gem has a dependency on json_web_token gem. So after I installed intuit-oauth gem, It automatically installed json_web_token gem. Due to this gem, the JWT object was changed. like when I click on access JWT in the console. It returns as JsonWebToken object. Maybe this gem overrides JWT gem. So for a temporary solution, I removed intuit-oauth gem. and it works fine. Thank you.

Rails 4.2.9 "cannot load such file" (multiple files)

So it's been a while since I fired up the old Rails server. It took a lot of tricks to even get the bundle to install... but eventually I upgraded from Rails 4.2.6 to 4.2.9. The bundle installs just fine. I'm on Ruby 2.3.0. But now the problem is... whenever I try to run:
rails s
I get the following error:
rails-html-sanitizer.rb:2:in `require': cannot load such file -- loofah (LoadError)
from /home/rainless/.rvm/gems/ruby-2.3.0#rails3.2.16/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `<top (required)>'
from /home/rainless/.rvm/gems/ruby-2.3.0#global/gems/bundler-1.7.9/lib/bundler/runtime.rb:76:in `require'
from /home/rainless/.rvm/gems/ruby-2.3.0#global/gems/bundler-1.7.9/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/rainless/.rvm/gems/ruby-2.3.0#global/gems/bundler-1.7.9/lib/bundler/runtime.rb:72:in `each'
Or some variation of that.
At first I was getting around this by uninstalling whatever the Gem that was said to be unable to load (in this case "loofah" but I've done it with many more), and then adding it to the Gemfile and installing it using Bundler. I now realize that the list is never-ending:
gem 'rails-html-sanitizer'
gem 'chronic'
gem 'multipart-post'
gem 'oauth-active-resource'
gem 'rack-test'
gem 'multi_json'
gem 'addressable'
gem 'orm_adapter'
All the above couldn't load. I ran Rails for years before this... and I know this isn't the way it's supposed to work. Any help/advice on what could be going wrong?
If you see carefully in the error message, it says ruby-2.3.0#rails3.2.16 but you mentioned "upgraded from Rails 4.2.6 to 4.2.9." . For some reason, it's still referring to rails3.2.16. Therefore it could be you need to install the rails-html-sanitizer globally. By the way, Loofah is only needed if you wanted to use it in a non-rails app. Refer to the docs here.
Rails Html Sanitizer is only intended to be used with Rails
applications. If you need similar functionality in non Rails apps
consider using Loofah directly (that's what handles sanitization under
the hood).
from /home/rainless/.rvm/gems/ruby-2.3.0#rails3.2.16/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `<top (required)>'

Using the stackdriver gem with Rails

I am interested in playing around with the various stackdriver offerings, but I can't seem to get it to work with Rails. I added stackdriver to my Gemfile, ran bundle install and have added the config blocks.
Here's the error I am getting:
/usr/local/opt/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/railties-4.2.7.1/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `google_cloud' for #<Rails::Application::Configuration:0x007fbc843e0c18> (NoMethodError)
from /Users/preston/projects/myapp/config/environments/development.rb:74:in `block in <top (required)>'
I have tried requiring the Gem manually, among other things, and it doesn't seem like the code is getting loaded.
It turned out to be an issue that was causing an old version of the stackdriver gem (0.2.2) to be used. This happened due to a conflict with a different Google gem.

Thinking Sphinx -- no indexes found in config file

Trying to use Thinking Sphinx for search. Followed this Railscast by homebrew installing TS and MySQL (though I'm using pg in my app, it's apparently required), adding these lines to my gemfile:
gem 'mysql2'
gem 'thinking-sphinx'
and putting the following in my model, below everything else
post.rb
class Post < ActiveRecord::Base
#...
define_index do
indexes content
indexes :name
end
end
Then I go into the terminal and try rake ts:index, but I get this error:
using config file '/Users/<personal>/rails_projects/<personal>/config/development.sphinx.conf'...
FATAL: no indexes found in config file '/Users/<personal>/rails_projects/<personal>/config/development.sphinx.conf'
Fished around on the internet and found nothing that quite answered this. I've tried running rake ts:configure (which doesn't complain) and then rake ts:index, but it doesn't work.
Some background: I just changed my terminal shell (to use zsh), which made all sorts of weird unexpected changes. I had to reinstall bundler, then re-bundle install all my gems, then independently gem install rake. Then I bundle updated for good measure. Now rake seems to work, but I still get the error.
The config file the error is grumbling about:
indexer
{
}
searchd
{
listen = 127.0.0.1:9306:mysql41
log = /Users/<personal>/rails_projects/<personal>/log/development.searchd.log
query_log = /Users/<personal>/rails_projects/<personal>/log/development.searchd.query.log
pid_file = /Users/<personal>/rails_projects/<personal>/log/development.sphinx.pid
workers = threads
binlog_path = /Users/<personal>/rails_projects/<personal>/tmp/binlog/development
}
Any ideas what's going on / what code the answer might be in?
INTERESTING UPDATE -- I followed the Q&A on this Google Group to enter my rails console and type "Post.sphinx_indexes.length", but I got this very different error in return. Looks like my model is somehow not getting access to the gem?
NoMethodError: undefined method `define_index' for #<Class:0x007f9c06c611b0>
from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/dynamic_matchers.rb:55:in `method_missing'
from /Users/<personal>/rails_projects/<personal>/app/models/post.rb:55:in `<class:Post>'
from /Users/<personal>/rails_projects/<personal>/app/models/post.rb:13:in `<top (required)>'
from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:469:in `load'
from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:469:in `block in load_file'
from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:639:in `new_constants_in'
from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:468:in `load_file'
from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:353:in `require_or_load'
from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:502:in `load_missing_constant'
from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:192:in `block in const_missing'
from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:190:in `each'
from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:190:in `const_missing'
from (irb):1
from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'irb(main):002:0>
Also posted this question to the Thinking Sphinx Google Group and got the answer there, so I'll paste it below. After answering the above question, I ran into another error and have followed up on it there, so if anyone wants more info, this discussion should hopefully continue to be helpful.
And I quote:
Hi Sasha The issue is that Thinking Sphinx's documentation is mostly
for v2, but v3 is what you're using (and much better). Index
definitions are now located in app/indices - the README is your best
source of information (but anything it doesn't cover is probably the
same as earlier versions):
https://github.com/pat/thinking-sphinx/blob/master/README.textile
Have a read through of that, move your index definition, and you
should be good to go. Any further issues, get in touch :)
-- Pat
After that issue, I ran into this one, which was apparently because Sphinx didn't have access to my PostgreSQL database.
indexing index 'post_core'...
ERROR: source 'post_core_0': unknown type 'pgsql'; skipping.
ERROR: index 'post_core': failed to configure some of the sources, will not index.
total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 0 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
I fixed this by uninstalling Sphinx and both gems (thinking_sphinx and mysql2), then brew installing Sphinx with both mysql and pgsql flags, then reinstalling the gems.
After that, rake ts:index worked like a charm.
Another possible source of error is in the naming of the folder and file. An extra space, or indicies spelt with an 'i' will not recognize the files and thus not generate any index.
Things that take yonks to see...
[and in my case happen not so infrequently!]

Rails undefined method `Initialize' in environment.rb

I am trying to integrate twitter/bootstrap in my very first rails app (followed this article http://www.opinionatedprogrammer.com/2011/11/twitter-bootstrap-on-rails/) and now I get this error which I am unable to understand/resolve.
new-host:Talker Talker$ rails s
=> Booting Thin
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Projects/Talker/config/environment.rb:4:in <top (required)>': undefined methodInitialize' for Rails:Module (NoMethodError)
from /Projects/Talker/config.ru:4:in require'
from /Projects/Talker/config.ru:4:inblock in '
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:51:in instance_eval'
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:51:ininitialize'
from /Projects/Talker/config.ru:1:in new'
from /Projects/Talker/config.ru:1:in'
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:40:in eval'
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/builder.rb:40:inparse_file'
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:200:in app'
from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/server.rb:46:inapp'
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:301:in wrapped_app'
from /.rvm/gems/ruby-1.9.2-p318/gems/rack-1.4.1/lib/rack/server.rb:252:instart'
from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/server.rb:70:in start'
from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:55:inblock in '
from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:50:in tap'
from /.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:50:in'
from script/rails:6:in require'
from script/rails:6:in'
This is how my environments.rb looks like
require File.expand_path('../application', FILE)
Rails.Initialize.run do |config|
config.gem 'mongo'
config.gem "mongo_mapper"
end
Talker::Application.initialize!
I am very new to rails so any help/direction is highly appreciated!
When following naren's instructions, have you removed the Rails.Initialize.run block from the environment.rb file? I know this probably may sound silly :)
Also, from the second error, I gather that you might be using Mongo HQ and if it is hosted on Heroku, they have a pretty detailed instruction manual on configuring your DB. Heroku MongoHQ Dev Center. Two things to check in your app:
Is the MongoDB url (Mongo HQ's url) is configured properly? This is because, the second error says that there may be a problem with the link itself.
Newer version of rails (3 and above) do not allow the config.gem syntax in the environment block. Rather, you need to add a initializer file in config/initializers. More on this on the MongoDB Documentation for Rails 3 section.
Hope this helps.
I think you do not need to specify config.gem in Rails.Initialize. In your Gemfile under project root directory specify the gems. You can remove the above
gem "mongo"
gem "mongo_mapper"
Then install gems using bundle install. Now you should be having the gems
Please try restarting after removing the Rails.Initialize block

Resources