Please help in solving the problem. Maybe I did something wrong or maybe I forgot to preinstall anything.

I took the code from the textbook:

require 'open-uri' open('http://pragprog.com') do |f| puts f.read.scan(/<img alt=".*?" src="(.*?)"/m).uniq[0,3] end 

knocks error:

 C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/open-uri.rb:223:in `open_loop': redirection forbidden: http://pragprog.com -> https://pragprog.com/ (Runti meError) from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/open-uri.rb:149:in `open_uri' from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/open-uri.rb:688:in `open' from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/open-uri.rb:34:in `open' from ./lib/methods.rb:123:in `<main>' 
  • Carefully look at the description of the error. There is an answer in it. - anoam
  • Jaw install something? - Gretel
  • I have already changed the link from http to https and back. Not fixed. - Gretel
  • And if you compare urls redirect even more carefully?) To make it easier, put url with https and see where it is trying to redirect. - anoam

1 answer 1

Indeed, the error message already contains information about what went wrong. Change the protocol from http to https in urla.

 require 'open-uri' open('https://pragprog.com') do |f| puts f.read.scan(/<img alt=".*?" src="(.*?)"/m).uniq[0,3] end