Search code examples
ruby-on-railsruby-on-rails-5open-uri

OpenURI::HTTPError: 401 Unauthorized with open-uri


I am trying to Hit my own server url with open() command but its says

OpenURI::HTTPError: 401 Unauthorized

from /.rbenv/versions/2.2.7/lib/ruby/2.2.0/open-uri.rb:358:in `open_http'

My domain name is let say http://example.com and i am trying to hit the url with open command that is

open("http://example.com/system/contract/abc")

But it gave the above error. On my localhost its working fine. Suggestion are appreciated.


Solution

  • the URL you're trying to access requires authentication. There are couple of example / answers to authentication questions using OpenURI in stackoverflow. Here are some of them:

    OpenUri causing 401 Unauthorized error with HTTPS URL

    and if you are using a proxy: Ruby open-uri proxy authentication fails