Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Strange NoMethodError

Reply
Thread Tools

Strange NoMethodError

 
 
Holger Biebinger
Guest
Posts: n/a
 
      08-07-2006
Hi,
In the following test script (similar to pickaxe p. 700 ):

require 'net/http'
require 'uri'

def fetch (uri_str, limit=10)
fail 'http redirect limit exceeded' if limit.zero?
response = Net::HTTP.get_response(URI.parse(uri_str))
case response
when Net::HTTPSuccess
response
when Net::HTTPRedirection
fetch(response['location'], limit-1)
else
response.error!
end
end


fetch('heise.de');


with
ruby test.rb
I get the result:

Exception `NoMethodError' at /usr/local/lib/ruby/1.8/net/http.rb:380
- undefined method `request_uri' for #<URI::Generic:0x188f84
URL:heise.de>
/usr/local/lib/ruby/1.8/net/http.rb:380:in `get_response': undefined
method `request_uri' for #<URI::Generic:0x188f84 URL:heise.de>
(NoMethodError)
from /usr/local/lib/ruby/1.8/net/http.rb:545:in `start'
from /usr/local/lib/ruby/1.8/net/http.rb:379:in `get_response'
from test.rb:6:in `fetch'
from test.rb:18


I had a look at /usr/local/lib/ruby/1.8/uri/http.rb
The function was defined there:
#
# == Description
#
# Returns: path + '?' + query
#
def request_uri
r = path_query
if r[0] != ?/
r = '/' + r
end

r
end

It should be a function of the standard libray. I am quite new to
ruby. How can I debug this problem? Or any hints what I can do?

Thanks in advance for your help,


Holger






 
Reply With Quote
 
 
 
 
ara.t.howard@noaa.gov
Guest
Posts: n/a
 
      08-07-2006
On Mon, 7 Aug 2006, Holger Biebinger wrote:

> Hi,
> In the following test script (similar to pickaxe p. 700 ):
>
> require 'net/http'
> require 'uri'
>
> def fetch (uri_str, limit=10)
> fail 'http redirect limit exceeded' if limit.zero?
> response = Net::HTTP.get_response(URI.parse(uri_str))
> case response
> when Net::HTTPSuccess
> response
> when Net::HTTPRedirection
> fetch(response['location'], limit-1)
> else
> response.error!
> end
> end
>
>
> fetch('heise.de');

^^^^^^^^
^^^^^^^^

this is not a uri.

try

harp:~ > ruby -r uri -e' p URI.parse("heise.de").host '
nil

harp:~ > ruby -r uri -e' p URI.parse("http://heise.de").host '
"heise.de"

regards.

-a
--
happiness is not something ready-made. it comes from your own actions.
- h.h. the 14th dali lama

 
Reply With Quote
 
 
 
 
Holger Biebinger
Guest
Posts: n/a
 
      08-07-2006
On Aug 7, 2006, at 5:02 PM, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> On Mon, 7 Aug 2006, Holger Biebinger wrote:
>
>> Hi,
>> In the following test script (similar to pickaxe p. 700 ):
>>
>> require 'net/http'
>> require 'uri'
>>
>> def fetch (uri_str, limit=10)
>> fail 'http redirect limit exceeded' if limit.zero?
>> response = Net::HTTP.get_response(URI.parse(uri_str))
>> case response
>> when Net::HTTPSuccess
>> response
>> when Net::HTTPRedirection
>> fetch(response['location'], limit-1)
>> else
>> response.error!
>> end
>> end
>>
>>
>> fetch('heise.de');

> ^^^^^^^^
> ^^^^^^^^
>
> this is not a uri.
>
> try
>
> harp:~ > ruby -r uri -e' p URI.parse("heise.de").host '
> nil
>
> harp:~ > ruby -r uri -e' p URI.parse("http://heise.de").host '
> "heise.de"
>
> regards.
>
> -a


Oh my god ... thank you vey much. You are right. I was a it confused
because of the NoMethodError and I thought I had installed something
wrongly. Thanks for your hint

best regards,
Holger

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
strange "NoMethodError" ??? Une bévue Ruby 0 07-16-2006 06:29 AM
Ruby On Rails, NoMethodError 'rewrite' Peter Barry Ruby 0 10-18-2005 11:46 AM
ActionMailer NoMethodError 'deliver' enspired Ruby 3 07-28-2005 03:18 PM
NoMethodError in Range#include? Levin Alexander Ruby 11 07-14-2005 02:47 PM
[BUG?] NoMethodError in REXML::Xpath.match in Ruby 1.9 Alexey Verkhovsky Ruby 0 08-03-2004 05:51 AM



Advertisments