open-uri 414 Request-URI Too Large

Discussion in 'Ruby' started by Jay 99, Apr 4, 2009.

  1. Jay 99

    Jay 99 Guest

    I am hitting a wall. This is my first attempt at ruby programming and I
    am sure my code leaves a lot to be desired...be gentle.

    I have a csv file I am loading into an array, it contains static pieces
    of a url that i build other urls from.

    It will loop through the first 10 in the array and always works. Number
    11 always fails with:

    C:/Ruby/lib/ruby/1.8/open-uri.rb:277:in `open_http': 414 Request-URI Too
    Large (
    OpenURI::HTTPError)
    from C:/Ruby/lib/ruby/1.8/open-uri.rb:616: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:518:in `open'
    from C:/Ruby/lib/ruby/1.8/open-uri.rb:30:in `open'

    So I shift my loop to start at 11 to the end and after the 10th time in
    the loop it fails. Shift it again by 10, same thing. A total of 58 array
    elements, csv file size is 44 KB. Rules out the data right?

    Leads me to believe that I have a memory problem or maybe I need to
    clear out the variable. The array data contains passwords and usernames
    so I will sanitize them and upload if needed.

    Here is the basic code.

    require 'rubygems'
    require 'hpricot'
    require 'open-uri'
    require 'csv'

    fluffers = Array.new

    urlA =
    "http://mywebpage.com/fight.php?investor_id=67814104&action=status"
    urlB = "http://mywebpage.com/bank.php?amount="
    urlB2 = "&action=Deposit&do=Deposit"
    urlH = "http://mywebpage.com/holy.php?cost=&action=Get%20personal"
    urlS = "http://mywebpage.com/index.php?"

    # Populate the array with the static information
    CSV.open('z:/ruby/invest2.csv', 'r') do |row|
    fluffers.push row
    end

    i = 0
    until i == fluffers.length
    doc = Hpricot(open(urlStatus << fluffers.to_s))
    inMoney =
    doc.search("//strong[@class='money']").inner_html.gsub(/\D/,'')
    inHoly = (doc/"#current_holy").inner_html
    inEnergy = (doc/"#current_energy").inner_html
    inStock = (doc/"#current_stock").inner_html

    if inMoney.to_i > 0
    open(urlB + inMoney + urlB2 + fluffers.to_s)
    print "deposit\n"
    end

    inStock.to_i.times do
    if inHoly.to_i < 20
    open(urlH + fluffers.to_s)
    end
    open(urlA + fluffers.to_s)
    print "a\n"
    doc = Hpricot(open(urlS << fluffers.to_s))
    inHoly = (doc/"#current_holy").inner_html
    print inHoly
    end
    i += 1
    end

    Thank You!
    --
    Posted via http://www.ruby-forum.com/.
    Jay 99, Apr 4, 2009
    #1
    1. Advertising

  2. Jay 99

    Ben Lovell Guest

    [Note: parts of this message were removed to make it a legal post.]

    Look at these lines:

    >
    > doc = Hpricot(open(urlStatus << fluffers.to_s))
    >


    And


    > doc = Hpricot(open(urlS << fluffers.to_s))
    >



    the urlStatus and urlS are getting larger each time this is called. You want
    to check which URI is being used as from the error message you get, it is
    clearly too large.

    Ben
    Ben Lovell, Apr 4, 2009
    #2
    1. Advertising

  3. Jay 99

    Jay 99 Guest

    Ben Lovell wrote:
    > the urlStatus and urlS are getting larger each time this is called. You want
    > to check which URI is being used as from the error message you get, it is
    > clearly too large.
    >
    > Ben


    Thanks!!! I changed it to a constant and it worked as needed.
    --
    Posted via http://www.ruby-forum.com/.
    Jay 99, Apr 4, 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. Luigi Donatello Asero

    Are these pictures too dark or/and too large?

    Luigi Donatello Asero, May 19, 2004, in forum: HTML
    Replies:
    13
    Views:
    899
    Mabden
    May 21, 2004
  2. Luigi Donatello Asero

    Re: Are these pictures too dark or/and too large?

    Luigi Donatello Asero, May 21, 2004, in forum: HTML
    Replies:
    0
    Views:
    636
    Luigi Donatello Asero
    May 21, 2004
  3. Vinay Sajip

    PEP 414 has been accepted

    Vinay Sajip, Feb 27, 2012, in forum: Python
    Replies:
    0
    Views:
    172
    Vinay Sajip
    Feb 27, 2012
  4. Dag Sunde
    Replies:
    4
    Views:
    345
  5. shin82

    problem with constant too too large

    shin82, Oct 31, 2012, in forum: C Programming
    Replies:
    0
    Views:
    342
    shin82
    Oct 31, 2012
Loading...

Share This Page