SocketError: getaddrinfo: nodename nor servname provided, or

I’m trying to use Net/Http and am getting the following error:

SocketError: getaddrinfo: nodename nor servname provided, or not known

I’m on Mac OS X, Leopard, check out my ruby version/gem env below.

Also, I double checked my etc/hosts and I do see an entry for
localhost/127.0.0.1 there. Seems like this is a Leopard issue?

[[email protected]:~]$ ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [universal-darwin9.0]

[[email protected]:~]$ gem environment
RubyGems Environment:

  • RUBYGEMS VERSION: 1.0.1 (1.0.1)
  • RUBY VERSION: 1.8.6 (2007-09-24 patchlevel 111)
    [universal-darwin9.0]
  • INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
  • RUBYGEMS PREFIX:
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby
  • RUBY EXECUTABLE:
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  • RUBYGEMS PLATFORMS:
    • ruby
    • universal-darwin-9
  • GEM PATHS:

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- /Library/Ruby/Gems/1.8

  • GEM CONFIGURATION:
    • :update_sources => true
    • :verbose => true
    • :benchmark => false
    • :backtrace => false
    • :bulk_threshold => 1000
  • REMOTE SOURCES:

Can we pleas see the code that is causing this error?

Try this:

require ‘net/http’
Net::HTTP.start(‘www.google.com’) do |http|
response = http.get(’/’)
puts response
end

#start doesn’t take the protocol.

Here’s the code:

require ‘net/http’
Net::HTTP.start(‘http://www.google.com’) do |http|
response = http.get(’/’)
puts response
end

Great, that did it!

Thanks Michael! (and I apologize to everyone who was spammed with this
message–I did do a google search & doc search but couldn’t find a
solution…)

Michael B. wrote:

Try this:

require ‘net/http’
Net::HTTP.start(‘www.google.com’) do |http|
response = http.get(’/’)
puts response
end

#start doesn’t take the protocol.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs