Simple http.get() script fails

Discussion in 'Ruby' started by Juan Medín, Dec 2, 2009.

  1. Hi,

    Using a simple test script to get Google's start page HTML gives me the
    following error:

    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in
    `initialize': getaddrinfo: nodename nor servname provided, or not known
    (SocketError)
    from
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in
    `open'


    The script is:

    USERAGENT = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US;
    rv:1.9.0.10) ' +
    'Gecko/2009042315 Firefox/3.0.10'

    http = Net::HTTP.new( 'http://www.google.com' )

    res = http.get( '/', {
    'User-Agent' => USERAGENT,
    'Accept' => '*/*',
    'Accept-Language' => 'en-us,en,q=0.5',
    'accept-encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
    'Connection' => 'keep-alive',
    'Keep-Alive' => '115'
    } )

    puts res.body


    Googling for it shows some results stating the there was an error with
    OS X 10.5.3 (I'm using 10.6.2) but I find hard to believe that the error
    is still there in such a core library, so the problem must be in my
    code.

    Can anyone provide some light on this? Thanks !
    --
    Posted via http://www.ruby-forum.com/.
     
    Juan Medín, Dec 2, 2009
    #1
    1. Advertising

  2. You could try:

    require 'open-uri'
    http = open('http:/www.google.com')

    http then contains your google page data.
    --
    Posted via http://www.ruby-forum.com/.
     
    Mike Stephens, Dec 2, 2009
    #2
    1. Advertising

  3. Juan Medín

    Nik Z. Guest

    Didn't you forget to put in your PROXY settings?? NodeName not found
    normally means you didn't even get out of your own network block...



    On Tue, Dec 1, 2009 at 11:29 PM, Juan Med=EDn <> wrote:

    > Hi,
    >
    > Using a simple test script to get Google's start page HTML gives me the
    > following error:
    >
    >
    > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/n=

    et/http.rb:560:in
    > `initialize': getaddrinfo: nodename nor servname provided, or not known
    > (SocketError)
    > from
    >
    > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/n=

    et/http.rb:560:in
    > `open'
    >
    >
    > The script is:
    >
    > USERAGENT =3D 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US;
    > rv:1.9.0.10) ' +
    > 'Gecko/2009042315 Firefox/3.0.10'
    >
    > http =3D Net::HTTP.new( 'http://www.google.com' )
    >
    > res =3D http.get( '/', {
    > 'User-Agent' =3D> USERAGENT,
    > 'Accept' =3D> '*/*',
    > 'Accept-Language' =3D> 'en-us,en,q=3D0.5',
    > 'accept-encoding' =3D> 'gzip;q=3D1.0,deflate;q=3D0.6,identity;q=3D0.3',
    > 'Connection' =3D> 'keep-alive',
    > 'Keep-Alive' =3D> '115'
    > } )
    >
    > puts res.body
    >
    >
    > Googling for it shows some results stating the there was an error with
    > OS X 10.5.3 (I'm using 10.6.2) but I find hard to believe that the error
    > is still there in such a core library, so the problem must be in my
    > code.
    >
    > Can anyone provide some light on this? Thanks !
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >
     
    Nik Z., Dec 2, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lasse Seten

    HTTP POST and GET fails

    Lasse Seten, Jul 23, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    363
    Lasse Seten
    Jul 23, 2003
  2. serge calderara

    HTTP GET vs HTTP POST protocol

    serge calderara, Nov 4, 2005, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    658
  3. n3d!m

    Http post and http get

    n3d!m, Jan 25, 2012, in forum: Python
    Replies:
    2
    Views:
    392
    n3d!m
    Feb 6, 2012
  4. Jeff Jortner
    Replies:
    1
    Views:
    138
    Jan Svitok
    Nov 3, 2006
  5. Wladimir Borsov
    Replies:
    4
    Views:
    324
    Tintin
    May 11, 2006
Loading...

Share This Page