3

Currently I am receiving an error message from eu central bank gem on rails as;

2018-09-06T18:26:20.629896+00:00 app[web.1]:   Error ID: 79f8e4f3
2018-09-06T18:26:20.629903+00:00 app[web.1]:   Error details saved to: /tmp/passenger-error.ZqeFNI
2018-09-06T18:26:20.629905+00:00 app[web.1]:   Message from application: redirection forbidden: http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml -> https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml (RuntimeError)
2018-09-06T18:26:20.629907+00:00 app[web.1]:   /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/open-uri.rb:224:in `open_loop'
2018-09-06T18:26:20.629908+00:00 app[web.1]:   /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/open-uri.rb:150:in `open_uri'
2018-09-06T18:26:20.629912+00:00 app[web.1]:   /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/open-uri.rb:716:in `open'
2018-09-06T18:26:20.629916+00:00 app[web.1]:   /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/open-uri.rb:34:in `open'
2018-09-06T18:26:20.629919+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/eu_central_bank-0.5.0/lib/eu_central_bank.rb:87:in `doc'
2018-09-06T18:26:20.629941+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/eu_central_bank-0.5.0/lib/eu_central_bank.rb:20:in `update_rates'
2018-09-06T18:26:20.629976+00:00 app[web.1]:   /app/config/initializers/money.rb:5:in `<top (required)>'
2018-09-06T18:26:20.630007+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
2018-09-06T18:26:20.630038+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
2018-09-06T18:26:20.630069+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
2018-09-06T18:26:20.630099+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
2018-09-06T18:26:20.630128+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/engine.rb:652:in `block in load_config_initializer'
2018-09-06T18:26:20.630158+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/notifications.rb:166:in `instrument'
2018-09-06T18:26:20.630205+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/engine.rb:651:in `load_config_initializer'
2018-09-06T18:26:20.630344+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
2018-09-06T18:26:20.630376+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in `each'
2018-09-06T18:26:20.630409+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in `block in <class:Engine>'
2018-09-06T18:26:20.630438+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
2018-09-06T18:26:20.630467+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
2018-09-06T18:26:20.630497+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'

I think there is a problem with the gem or the xml folder. But it happened suddenly. The application is closed right now on rails. Can not change the link from http to https

Shalafister's
  • 761
  • 1
  • 7
  • 34

1 Answers1

7

Apparently, you are facing the same problem as this one:

Ruby open-uri redirect forbidden

It's caused because the EU central bank forced a redirection to https but openuri library is not allowing this and that's why you get this error: redirection forbidden.

There is a gem called open_uri_redirections that will patch the openuri to allow redirections.

https://github.com/open-uri-redirections/open_uri_redirections

All you need to do is to:

  • include this gem in your Gemfile.
  • $ bundle install to install the newly added gem.
  • require 'open_uri_redirections'

This should fix your issue temporarily.


Another fix (recommended) is to monkey patch eu_central_bank gem to override

ECB_RATES_URL at eu_central_bank/lib/eu_central_bank.rb:20

ECB_90_DAY_URL at eu_central_bank/lib/eu_central_bank.rb:21

constants with https instead of http.

as follows (put this code to config/initializers/patch_eu_central_bank.rb):

require 'eu_central_bank'
class EuCentralBank
  ECB_RATES_URL = 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'.freeze
  ECB_90_DAY_URL = 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml'.freeze
end

You might see some warnings like:

warning: already initialized constant EuCentralBank::ECB_RATES_URL.

You can live with it till the PR merged at the EuCentralBank gem.

Tarek N. Elsamni
  • 1,718
  • 1
  • 12
  • 15
  • Thank you for your help. Some people already suggested this, and I am trying to get it as `gem 'eu_central_bank', github: 'RubyMoney/eu_central_bank', ref: 'e7410a5c8cbb8f12e47da6ab0bc1f1246049bd52'` But this time it gives error; `fatal: Could not parse object 'e7410a5c8cbb8f12e47da6ab0bc1f1246049bd52'. Git error: command `git reset --hard e7410a5c8cbb8f12e47da6ab0bc1f1246049bd52 in directory /Users/jack/.rvm/gems/ruby-2.2.6/bundler/gems/eu_central_bank-e7410a5c8cbb has failed.` – Shalafister's Sep 06 '18 at 20:37
  • For the first solution, where shall I add `require 'open_uri_redirections'`? – Shalafister's Sep 06 '18 at 20:42
  • in `config/initializers/patch_open_uri.rb` – Tarek N. Elsamni Sep 06 '18 at 20:44
  • I don't know why you are getting this error from your `Gemfile` but you can also monkey patch the URL to `https` yourself temporarily. I'll update my code to show how to do this – Tarek N. Elsamni Sep 06 '18 at 20:45
  • Thank you for your help! – Shalafister's Sep 06 '18 at 20:50
  • Try this: `gem 'eu_central_bank', github: 'Etison/eu_central_bank', branch: 'use_https' ` – Tarek N. Elsamni Sep 06 '18 at 20:50
  • 1
    This gave the same error. But I used your recommended solution and I will wait for the merge. Thank you again! – Shalafister's Sep 06 '18 at 20:52