open_uri.rb -- 500 Internal Server Error

Discussion in 'Ruby' started by Vikas Gholap, Jan 17, 2009.

  1. Vikas Gholap

    Vikas Gholap Guest

    Hello to all,
    I am using 'open-uri' & 'pp' ruby library, to open url and gather some
    data from given web page. But it throws following error

    c:/ruby/lib/ruby/1.8/open-uri.rb:278:in `open_http': 500 Internal Server
    Error (
    OpenURI::HTTPError)
    from c:/ruby/lib/ruby/1.8/open-uri.rb:617:in `buffer_open'
    from c:/ruby/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
    from c:/ruby/lib/ruby/1.8/open-uri.rb:162:in `catch'
    from c:/ruby/lib/ruby/1.8/open-uri.rb:162:in `open_loop'
    from c:/ruby/lib/ruby/1.8/open-uri.rb:132:in `open_uri'
    from c:/ruby/lib/ruby/1.8/open-uri.rb:519:in `open'
    from c:/ruby/lib/ruby/1.8/open-uri.rb:30:in `open'
    from openmyurl.rb:4


    source code openurl.rb is like-----


    require 'open-uri'
    require 'pp'

    open('http://www.aflatune.com/') do |f|
    # hash with meta information
    pp f.meta

    #
    pp "Content-Type: " + f.content_type
    pp "last modified" + f.last_modified.to_s

    no = 1
    # print the first fifty lines
    f.each do |line|
    print "#{no}: #{line}"
    no += 1
    break if no > 50
    end
    end

    can any one give me solution to how to solve this problem?
    --
    Posted via http://www.ruby-forum.com/.
     
    Vikas Gholap, Jan 17, 2009
    #1
    1. Advertising

  2. Vikas Gholap

    badboy Guest

    Vikas Gholap schrieb:
    > Hello to all,
    > I am using 'open-uri' & 'pp' ruby library, to open url and gather some
    > data from given web page. But it throws following error
    >
    > c:/ruby/lib/ruby/1.8/open-uri.rb:278:in `open_http': 500 Internal Server
    > Error (
    > OpenURI::HTTPError)
    > from c:/ruby/lib/ruby/1.8/open-uri.rb:617:in `buffer_open'
    > from c:/ruby/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
    > from c:/ruby/lib/ruby/1.8/open-uri.rb:162:in `catch'
    > from c:/ruby/lib/ruby/1.8/open-uri.rb:162:in `open_loop'
    > from c:/ruby/lib/ruby/1.8/open-uri.rb:132:in `open_uri'
    > from c:/ruby/lib/ruby/1.8/open-uri.rb:519:in `open'
    > from c:/ruby/lib/ruby/1.8/open-uri.rb:30:in `open'
    > from openmyurl.rb:4
    >
    >
    > source code openurl.rb is like-----
    >
    >
    > require 'open-uri'
    > require 'pp'
    >
    > open('http://www.aflatune.com/') do |f|
    > # hash with meta information
    > pp f.meta
    >
    > #
    > pp "Content-Type: " + f.content_type
    > pp "last modified" + f.last_modified.to_s
    >
    > no = 1
    > # print the first fifty lines
    > f.each do |line|
    > print "#{no}: #{line}"
    > no += 1
    > break if no > 50
    > end
    > end
    >
    > can any one give me solution to how to solve this problem?

    looks like the aflatune-Webserver throws a 500 error if no User-Agent is
    set.

    this works for me:
    open('http://www.aflatune.com/', 'User-Agent'=>'ruby')
     
    badboy, Jan 17, 2009
    #2
    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. John Bonds
    Replies:
    2
    Views:
    2,820
    Amaryllis
    Aug 3, 2004
  2. Replies:
    5
    Views:
    80,800
    cpdarkman
    Aug 26, 2009
  3. BobbyOwens
    Replies:
    0
    Views:
    4,699
    BobbyOwens
    Jan 23, 2009
  4. Replies:
    0
    Views:
    811
  5. Keith Carter
    Replies:
    3
    Views:
    142
    John Powers
    May 4, 2009
Loading...

Share This Page