"Moved Temporarily"?

When trying to run the following code from “Programming Ruby” I get an
error message stating
Fetching: www.rubycentral.com
Fetching: www.awl.com
Fetching: www.pragmaticprogrammer.com
Got www.rubycentral.com: OK
/usr/lib/ruby/1.6/net/protocol.rb:221:in error!': 302 "Moved Temporarily" (Net::ProtoRetriableError) from /Users/ilanterrell/Documents/ RubyScripts/threads.rb:20:injoin’
from /Users/ilanterrell/Documents/ RubyScripts/threads.rb:20
from /Users/ilanterrell/Documents/ RubyScripts/threads.rb:20:in
`each’
from /Users/ilanterrell/Documents/ RubyScripts/threads.rb:20
I am pretty new to ruby and I don’t have the slightest clue what “Moved
Temporarily” means. I have tried this on multiple platforms and get the
same error. Any ideas?

#!/usr/bin/ruby
require ‘net/http’

pages = %w( www.rubycentral.com
www.awl.com
www.pragmaticprogrammer.com
)
threads = []

for page in pages
threads << Thread.new(page) { |myPage|

h = Net::HTTP.new(myPage, 80)
puts "Fetching: #{myPage}"
resp, data = h.get(’/’, nil )
puts “Got #{myPage}: #{resp.message}”
}
end

threads.each { |aThread| aThread.join }

ーテレル イラン

Ila’n Terrell wrote:

/usr/lib/ruby/1.6/net/protocol.rb:221:in `error!': 302 "Moved

I am pretty new to ruby and I don’t have the slightest clue what “Moved
Temporarily” means. I have tried this on multiple platforms and get the
same error. Any ideas?

That’s an HTTP error code; I don’t believe it has anything to do with the Ruby code, other than that it’s passing on what the web server sent it.

I would imagine what the error means is that the web page has been moved to some other location.

Cheers,

Harry O.

That’s an HTTP error code; I don’t believe it has anything to do with
the Ruby code, other than that it’s passing on what the web server
sent it.

Exactly right.

I would imagine what the error means is that the web page has been
moved to some other location.

It does. The headers that are returned in that request should include
one labelled “Location:”, which is the new URL.

“302” means that the old URL should still be used, and is /not/
obsolete. If it were “301”, you should change the URL and use the new
one, always.

Ari

“Harry Ohlsen” harryo@qiqsolutions.com wrote in message
news:3F5D1667.9080200@qiqsolutions.com

Ila’n Terrell wrote:

/usr/lib/ruby/1.6/net/protocol.rb:221:in `error!': 302 "Moved

I am pretty new to ruby and I don’t have the slightest clue what “Moved
Temporarily” means. I have tried this on multiple platforms and get the
same error. Any ideas?

That’s an HTTP error code; I don’t believe it has anything to do
with the Ruby code, other than that it’s passing on what the web server
sent it.

Yes, but if you run it using ruby 1.8.0 it does not throw any error,
just displays the HTTP error (along with some warnings).
On Windows XP Pro (using /\ndy’s one-click installer)

···

C:\atest>type tst_http2.rb
#!/usr/bin/ruby
require ‘net/http’

pages = %w( www.rubycentral.com
www.awl.com
www.pragmaticprogrammer.com
)
threads =

for page in pages
threads << Thread.new(page) { |myPage|

h = Net::HTTP.new(myPage, 80)
puts “Fetching: #{myPage}”
resp, data = h.get(‘/’, nil )
puts “Got #{myPage}: #{resp.message}”
}
end

threads.each { |aThread| aThread.join }

C:\atest>ruby -v tst_http2.rb
ruby 1.8.0 (2003-08-04) [i386-mswin32]
Fetching: www.rubycentral.com
Fetching: www.awl.com
Fetching: www.pragmaticprogrammer.com
net/http: warning: old style assignment found at tst_http2.rb:15
Got www.rubycentral.com: OK
net/http: warning: old style assignment found at tst_http2.rb:15
Got www.awl.com: Moved Temporarily
net/http: warning: old style assignment found at tst_http2.rb:15
Got www.pragmaticprogrammer.com: OK

C:\atest>

“Harry Ohlsen” harryo@qiqsolutions.com wrote in message
news:3F5D1667.9080200@qiqsolutions.com

Ila’n Terrell wrote:

/usr/lib/ruby/1.6/net/protocol.rb:221:in `error!': 302 "Moved

I am pretty new to ruby and I don’t have the slightest clue what
“Moved
Temporarily” means. I have tried this on multiple platforms and get
the
same error. Any ideas?

That’s an HTTP error code; I don’t believe it has anything to do
with the Ruby code, other than that it’s passing on what the web
server
sent it.

In this case, the page is detecting the language that’s appropriate for
the visitor and redirecting them to the English or the Japanese page:

% telnet www.ruby-lang.org 80
Trying 210.251.121.214…
Connected to www.ruby-lang.org.
Escape character is ‘^]’.
GET / HTTP/1.1
Host: www.ruby-lang.org

HTTP/1.1 301 Moved Permanently
Server: Apache/1.3.26 (Unix) Debian GNU/Linux mod_ruby/0.9.7 Ruby/1.6.7
Location: Ruby Programming Language
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1

f2

301 Moved Permanently

Moved Permanently

The document has moved here.

Yes, but if you run it using ruby 1.8.0 it does not throw any error,
just displays the HTTP error (along with some warnings).
On Windows XP Pro (using /\ndy’s one-click installer)

Between 1.6.X and 1.8 the Net::HTTP module has changed, you should use:

resp = h.get(‘/’, nil )

rather than:

resp, data = h.get(‘/’, nil )

The other difference is that in 1.8, a 300 series error (a redirect) is
no longer an exception. Instead, you have to examine the return codes
and check to see if it was a redirect, using something like:

def getPage(url, header_hash, retry_count)

raise(“Too many redirects”) if 10 < retry_count

case response
when Net::HTTPSuccess
response
when Net::HTTPRedirection
getPage(url.merge(URI.parse(response[‘location’])),
header_hash,
retry_count + 1)
else
response.error!
end
end

Ben

···

On Monday, September 8, 2003, at 09:00 PM, Shashank Date wrote:
Date: Tue, 09 Sep 2003 01:56:02 GMT

“Ben Giddings” bg-rubytalk@infofiend.com wrote in message

The other difference is that in 1.8, a 300 series error (a redirect) is
no longer an exception. Instead, you have to examine the return codes
and check to see if it was a redirect, using something like:

def getPage(url, header_hash, retry_count)

raise(“Too many redirects”) if 10 < retry_count

case response
when Net::HTTPSuccess
response
when Net::HTTPRedirection
getPage(url.merge(URI.parse(response[‘location’])),
header_hash,
retry_count + 1)
else
response.error!
end
end

Ben

Thanks for sharing this insight, Ben.
– shanko