# Open\_uri.rb -- 500 Internal Server Error

**URL:** <https://www.ruby-forum.com/t/open-uri-rb-500-internal-server-error/157973>\
**Category:** Ruby\
**Created:** [January 17, 2009, 6:03am UTC](https://www.ruby-forum.com/t/open-uri-rb-500-internal-server-error/157973 "2009-01-17T06:03:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [January 17, 2009, 6:03am UTC](https://www.ruby-forum.com/t/open-uri-rb-500-internal-server-error/157973/1 "2009-01-17T06:03:30Z")

</div>

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/](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?

---

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [January 17, 2009, 1:02pm UTC](https://www.ruby-forum.com/t/open-uri-rb-500-internal-server-error/157973/2 "2009-01-17T13:02:29Z")

</div>

Vikas G. schrieb:

> ```
> from c:/ruby/lib/ruby/1.8/open-uri.rb:162:in `open_loop'
> 
> ```
> 
> require ‘pp’
> 
> # 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/](http://www.aflatune.com/)’, ‘User-Agent’=\>‘ruby’)
