Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenURI 403 Error on Heroku, Ruby on Rails 4
    primarykey
    data
    text
    <p>I'm using Rails 4 with Ruby 2, deployed on Heroku. My application uses OpenURI to open a Webpage (then passes the HTML to Nokogiri for parsing). On my local machine this works fine; on Heroku, I receive a 403 Error when the program arrives at the line with the <code>open</code> method. I have already done the following:</p> <ul> <li>Required <code>open-uri</code> in my application</li> <li>Added the <code>'User-Agent'</code> key to my <code>open</code> method call</li> <li>Included all required Heroku compatibility gems in my Gemfile as specified <a href="https://devcenter.heroku.com/articles/getting-started-with-rails4#heroku-gems" rel="nofollow">here</a></li> </ul> <p>Here's the offending line:</p> <pre><code>doc = Nokogiri::HTML(open(url, 'User-Agent' =&gt; "Ruby/#{RUBY_VERSION}")) </code></pre> <p>Here are the relevant (I believe) Heroku logs:</p> <pre><code>2013-10-22T01:20:53.281117+00:00 app[web.1]: Started POST "/texts/parse" for 66. 31.247.63 at 2013-10-22 01:20:53 +0000 2013-10-22T01:20:53.281117+00:00 app[web.1]: Started POST "/texts/parse" for 66. 31.247.63 at 2013-10-22 01:20:53 +0000 2013-10-22T01:20:53.287518+00:00 app[web.1]: Processing by TextsController#parse as HTML 2013-10-22T01:20:53.287518+00:00 app[web.1]: Processing by TextsController#parse as HTML 2013-10-22T01:20:53.287692+00:00 app[web.1]: Parameters: {"utf8"=&gt;"???", "auth enticity_token"=&gt;"zKqzrI7qaDjav1HA56kdiNi01Mgbavg4Xhff+t4bDh0=", "url"=&gt;"http:// www.gutenberg.org/files/135/135-h/135-h.htm", "commit"=&gt;"Import"} 2013-10-22T01:20:53.287692+00:00 app[web.1]: Parameters: {"utf8"=&gt;"???", "auth enticity_token"=&gt;"zKqzrI7qaDjav1HA56kdiNi01Mgbavg4Xhff+t4bDh0=", "url"=&gt;"http:// www.gutenberg.org/files/135/135-h/135-h.htm", "commit"=&gt;"Import"} 2013-10-22T01:20:44.346845+00:00 heroku[web.1]: Starting process with command `b in/rails server -p 30331 -e $RAILS_ENV` 2013-10-22T01:20:53.536799+00:00 app[web.1]: Completed 500 Internal Server Error in 247ms 2013-10-22T01:20:53.536799+00:00 app[web.1]: Completed 500 Internal Server Error in 247ms 2013-10-22T01:20:53.537796+00:00 app[web.1]: 2013-10-22T01:20:53.537796+00:00 app[web.1]: OpenURI::HTTPError (403 Forbidden): 2013-10-22T01:20:53.537796+00:00 app[web.1]: app/controllers/texts_controller. rb:75:in `parse' 2013-10-22T01:20:53.537796+00:00 app[web.1]: 2013-10-22T01:20:53.537796+00:00 app[web.1]: 2013-10-22T01:20:53.537796+00:00 app[web.1]: 2013-10-22T01:20:53.537796+00:00 app[web.1]: OpenURI::HTTPError (403 Forbidden): 2013-10-22T01:20:53.537796+00:00 app[web.1]: app/controllers/texts_controller. rb:75:in `parse' </code></pre> <p>I've done a lot of searching and can't find a fix. Usually the problem is that people forget to require <code>'open-uri'</code> in their application. Any help is greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload