eRuby giving problems with http.rb

Hi,
I have downloaded a piece of code in ruby that will get quotes from
Yahoo Finance. The code is pasted below:

require ‘yahoofinance’
require ‘open-uri’
require ‘rexml/document’
require ‘pp’
require ‘net/http.rb’

Set the type of quote we want to retrieve.

Available type are:

- YahooFinanace::StandardQuote

- YahooFinanace::ExtendedQuote

- YahooFinanace::RealTimeQuote

quote_type = YahooFinance::StandardQuote

Set the symbols for which we want to retrieve quotes.

You can include more than one symbol by separating

them with a ‘,’ (comma).

quote_symbols = “500570.BO”
#quote_symbols = “YHOO”

Get the quotes from Yahoo! Finance. The get_quotes method call

returns a Hash containing one quote object of type “quote_type” for

each symbol in “quote_symbols”. If a block is given, it will be

called with the quote object (as in the example below).

YahooFinance::get_quotes( quote_type, quote_symbols ) do |qt|
puts “QUOTING: #{qt.symbol}”
puts qt.to_s
end

You can get the same effect using the quote specific method.

quotes = YahooFinance::get_standard_quotes( quote_symbols )
quotes.each do |symbol, qt|
puts “QUOTING: #{symbol}”
puts qt.to_s
end

The above piece of code works fine when i use this directly in a .rb
file like this:
ruby testyahoo.rb
I get the stock quotes correctly.

But i have problems if i put exactly the same code between html tags
call it this way:
eruby testyahoo.rhtml
Code for testyahoo.rhtml file is pasted below:

#!C:/appdev/ruby/bin/eruby.exe

eruby test

eruby test

<%
require ‘yahoofinance’
require ‘open-uri’
require ‘rexml/document’
require ‘pp’
require ‘net/http.rb’

Set the type of quote we want to retrieve.

Available type are:

- YahooFinanace::StandardQuote

- YahooFinanace::ExtendedQuote

- YahooFinanace::RealTimeQuote

quote_type = YahooFinance::StandardQuote

Set the symbols for which we want to retrieve quotes.

You can include more than one symbol by separating

them with a ‘,’ (comma).

quote_symbols = “500570.BO”
#quote_symbols = “YHOO”

Get the quotes from Yahoo! Finance. The get_quotes method call

returns a Hash containing one quote object of type “quote_type” for

each symbol in “quote_symbols”. If a block is given, it will be

called with the quote object (as in the example below).

YahooFinance::get_quotes( quote_type, quote_symbols ) do |qt|
puts “QUOTING: #{qt.symbol}”
puts qt.to_s
end

You can get the same effect using the quote specific method.

quotes = YahooFinance::get_standard_quotes( quote_symbols )
quotes.each do |symbol, qt|
puts “QUOTING: #{symbol}”
puts qt.to_s
end

%>

I have attached a screen capture of the errors when the .rhtml file is
executed.
I am not able to figure out if my eruby installation is wrong or if my
path settings are incorrect. I tried eruby with other pieces of code
that dont need http.rb and these pieces of code work absolutely fine.

I have ruby, rubygems, eruby, mysql and apache running on a windows
vista system.

Any inputs would help.

Thanks & Regards
Aditya

On Feb 2, 2008 4:30 PM, Adi N. [email protected] wrote:

I have attached a screen capture of the errors when the .rhtml file is
executed.
I am not able to figure out if my eruby installation is wrong or if my
path settings are incorrect. I tried eruby with other pieces of code
that dont need http.rb and these pieces of code work absolutely fine.

(Without reading your full post:) The error says dns doesn’t work.
Either your connection is down, or you have wrong dns setting,
or you have a typo somewhere, causing dns resoultion to fail.

Or, yahoo changed their host-naming scheme and the library doesn’t
reflect that yet.

HTH,

Jano

Jano S. wrote:

On Feb 2, 2008 4:30 PM, Adi N. [email protected] wrote:

I have attached a screen capture of the errors when the .rhtml file is
executed.
I am not able to figure out if my eruby installation is wrong or if my
path settings are incorrect. I tried eruby with other pieces of code
that dont need http.rb and these pieces of code work absolutely fine.

(Without reading your full post:) The error says dns doesn’t work.
Either your connection is down, or you have wrong dns setting,
or you have a typo somewhere, causing dns resoultion to fail.

Or, yahoo changed their host-naming scheme and the library doesn’t
reflect that yet.

HTH,

Jano

Hi Ajno,
Thanks for the reply.
I just have a couple of questions here.
You have given me a list of possible errors. Are any of these specific
to eRuby? I do not have any problme with the same code executed as a .rb
file through ruby but i have it only when i execute it as a .rhtml
through eruby.

Thanks and Regards
Aditya.

Jano S. wrote:

On Feb 2, 2008 7:24 PM, Adi N. [email protected] wrote:

Hi Ajno,
Thanks for the reply.
I just have a couple of questions here.
You have given me a list of possible errors. Are any of these specific
to eRuby? I do not have any problme with the same code executed as a .rb
file through ruby but i have it only when i execute it as a .rhtml
through eruby.

Hi,

as I have written, I haven’t read your full post :wink: So, after your
questions, I guess there’s a problem with rights somewhere.
You may try to simplify your tests to a simple http request, although
it won’t help much (except it might be faster to check).

Vista’s rights are tighter than XP. Some hints what you can try:

  1. shutdown firewall if you have any
  2. running apache under normal user if you run it as a service
  3. run rhtml under webrick to see if it makes a difference
  4. run your standalone script as a cgi. it won’t get any input, but
    the error should be logged somewhere in the apache logs
    (don’t forget proper shebang line)
  5. examine apache and system logs (sorry if it’s too obvious)

I haven’t use eruby on windows, so these are just guesses.

Jano

Hi Jano,
Thanks a lot for your time.

Just to put things in perspective…the eruby error springs up even when
i run the script from the command prompt. Thats the reason i have
stopped doubting apache now.
So, i shall first check firewall settings and dns settings.
Do you know of some website where i can find more info on this problem ?

Thanks & Regards
Aditya.

On Feb 2, 2008 7:24 PM, Adi N. [email protected] wrote:

Hi Ajno,
Thanks for the reply.
I just have a couple of questions here.
You have given me a list of possible errors. Are any of these specific
to eRuby? I do not have any problme with the same code executed as a .rb
file through ruby but i have it only when i execute it as a .rhtml
through eruby.

Hi,

as I have written, I haven’t read your full post :wink: So, after your
questions, I guess there’s a problem with rights somewhere.
You may try to simplify your tests to a simple http request, although
it won’t help much (except it might be faster to check).

Vista’s rights are tighter than XP. Some hints what you can try:

  1. shutdown firewall if you have any
  2. running apache under normal user if you run it as a service
  3. run rhtml under webrick to see if it makes a difference
  4. run your standalone script as a cgi. it won’t get any input, but
    the error should be logged somewhere in the apache logs
    (don’t forget proper shebang line)
  5. examine apache and system logs (sorry if it’s too obvious)

I haven’t use eruby on windows, so these are just guesses.

Jano

Hi Jano,
Thanks a lot for your time.

Just to put things in perspective…the eruby error springs up even when
i run the script from the command prompt. Thats the reason i have
stopped doubting apache now.
So, i shall first check firewall settings and dns settings.
Do you know of some website where i can find more info on this problem ?

In april, there was similar problem in the thread “eruby & Mechanize
error” unfortunately without answer.
I have tried your script under xp and it does not work either.

What worked for me: use erb or erubis instead of eruby. Erubis may be
even faster, though I won’t tell
you how to plug it into apache.

It seems that eruby’s build (eruby-1.0.5-i386-mswin32-1.8.zip) has
compatibility problem with current ruby (1.8.6-p111)

Jano S. wrote:

On Feb 4, 2008 1:46 PM, Jano S. [email protected] wrote:

What worked for me: use erb or erubis instead of eruby.

Just a note:

erb - bundled in one-click
erubis - gem install erubis

use erb.cmd or erubis.cmd (or ruby.exe c:/ruby/bin/erubis
) instead of eruby.exe

Hi Jano,
Thanks a lot.
Shall try the same and let you know the results.
Compatibility issue is my guess as well since the same code ahs not
hhhp.rb problems with ruby.exe but has problems with eruby.exe.

Regards
Adi.

On Feb 4, 2008 1:46 PM, Jano S. [email protected] wrote:

What worked for me: use erb or erubis instead of eruby.

Just a note:

erb - bundled in one-click
erubis - gem install erubis

use erb.cmd or erubis.cmd (or ruby.exe c:/ruby/bin/erubis
) instead of eruby.exe