# Open-uri 414 Request-URI Too Large

**URL:** <https://www.ruby-forum.com/t/open-uri-414-request-uri-too-large/164693>\
**Category:** Ruby\
**Created:** [April 4, 2009, 3:24am UTC](https://www.ruby-forum.com/t/open-uri-414-request-uri-too-large/164693 "2009-04-04T03:24:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jay99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/958977/32.png) [@jay99](https://www.ruby-forum.com/u/jay99)\
**Post date:** [April 4, 2009, 3:24am UTC](https://www.ruby-forum.com/t/open-uri-414-request-uri-too-large/164693/1 "2009-04-04T03:24:13Z")

</div>

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 =  
“[mywebpage.com&nbsp;-&nbsp;This website is for sale!&nbsp;-&nbsp;mywebpage Resources and Information.](http://mywebpage.com/fight.php?investor_id=67814104&action=status)”  
urlB = “[mywebpage.com&nbsp;-&nbsp;This website is for sale!&nbsp;-&nbsp;mywebpage Resources and Information.](http://mywebpage.com/bank.php?amount=)”  
urlB2 = “&action=Deposit&do=Deposit”  
urlH = “[mywebpage.com&nbsp;-&nbsp;This website is for sale!&nbsp;-&nbsp;mywebpage Resources and Information.](http://mywebpage.com/holy.php?cost=&action=Get%20personal)”  
urlS = “[mywebpage.com&nbsp;-&nbsp;This website is for sale!&nbsp;-&nbsp;mywebpage Resources and Information.](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[i].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[i].to\_s)  
print “deposit\n”  
end

inStock.to\_i.times do  
if inHoly.to\_i \< 20  
open(urlH + fluffers[i].to\_s)  
end  
open(urlA + fluffers[i].to\_s)  
print “a\n”  
doc = Hpricot(open(urlS \<\< fluffers[i].to\_s))  
inHoly = (doc/“#current\_holy”).inner\_html  
print inHoly  
end  
i += 1  
end

Thank You!

---

<div class="post-metadata">

**Author:** ![jay99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/958977/32.png) [@jay99](https://www.ruby-forum.com/u/jay99)\
**Post date:** [April 4, 2009, 1:24pm UTC](https://www.ruby-forum.com/t/open-uri-414-request-uri-too-large/164693/2 "2009-04-04T13:24:58Z")

</div>

Look at these lines:

> doc = Hpricot(open(urlStatus \<\< fluffers[i].to\_s))

And

> doc = Hpricot(open(urlS \<\< fluffers[i].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

---

<div class="post-metadata">

**Author:** ![jay99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/958977/32.png) [@jay99](https://www.ruby-forum.com/u/jay99)\
**Post date:** [April 4, 2009, 2:11pm UTC](https://www.ruby-forum.com/t/open-uri-414-request-uri-too-large/164693/3 "2009-04-04T14:11:03Z")

</div>

Ben L. 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.
