OpenURI is a Ruby module included in the standard library, which provides an easy-to-use wrapper for net/http, net/https and net/ftp.
Questions tagged [open-uri]
311 questions
9
votes
2 answers
`open_http': 403 Forbidden (OpenURI::HTTPError) for the string "Steve_Jobs" but not for any other string
I was going through the Ruby tutorials provided at http://ruby.bastardsbook.com/ and I encountered the following code:
require "open-uri"
remote_base_url = "http://en.wikipedia.org/wiki"
r1 = "Steve_Wozniak"
r2 = "Steve_Jobs"
f1 = "my_copy_of-" +…

Yahoo-Me
- 4,933
- 5
- 27
- 26
8
votes
1 answer
Ruby/Rails Performance: OpenURI vs NET:HTTP vs Curb vs Rest-Client
I'm accessing different servers for data and I tried different methods in different classes, using the basic http::net, curb, rest-client and open-uri
(1) How to measure performance in Ruby / Rails in General?
(2) Which method do you think is…
user1781626
8
votes
1 answer
URI Response Code
I would like to use Ruby's OpenURI to check whether the URL can be properly accessed. So I would like to check its response code (4xx or 5xx means error, etc.) Is it possible to find that?

Mika H.
- 4,119
- 11
- 44
- 60
8
votes
2 answers
Ruby - How to get the name of a file with open-uri?
I want to download a music file by this way:
require 'open-uri'
source_url = "http://soundcloud.com/stereo-foo/cohete-amigo/download"
attachment_file = "test.wav"
open(attachment_file, "wb") do |file|
file.print open(source_url).read
end
In…

ElektroStudios
- 19,105
- 33
- 200
- 417
7
votes
1 answer
resque-web fails to start with a 500 Server Error
I'm following the configuration guidelines for installing resque. I'm met with a (OpenURI::HTTPError). I'm using RVM 1.9.2-p180, rails 3.0.6, and POW.'resque-web' fails to start with a 500 Server Error. What the heck is going on here?
To replicate…

JZ.
- 21,147
- 32
- 115
- 192
7
votes
1 answer
open-uri returning ASCII-8BIT from webpage encoded in iso-8859
I am using open-uri to read a webpage which claims to be encoded in iso-8859-1. When I read the contents of the page, open-uri returns a string encoded in ASCII-8BIT.
open("http://www.nigella.com/recipes/view/DEVILS-FOOD-CAKE-5310") {|f| p…

mkhettry
- 71
- 1
- 2
7
votes
2 answers
Ruby File IO: Can't open url as File object
I have a function in my code that takes a string representing the url of an image and creates a File object from that string, to be attached to a Tweet. This seems to work about 90% of the time, but occasionally fails.
require…

Daniel Bonnell
- 4,817
- 9
- 48
- 88
7
votes
3 answers
Using OpenUri, how can I get the contents of a redirecting page?
I want to get data from this page:
http://www.canadapost.ca/cpotools/apps/track/personal/findByTrackNumber?trackingNumber=0656887000494793
But that page forwards…

Shpigford
- 24,748
- 58
- 163
- 252
7
votes
1 answer
Ruby: Force open-uri to return IPv4 address
In our Rails app, we have a controller action that opens an external URL, and returns it as JSON for our front end to consume.
Today, I got the following error:
Errno::EAFNOSUPPORT: Address family not supported by protocol - socket(2)
Our devops…

nickcoxdotme
- 6,567
- 9
- 46
- 72
7
votes
1 answer
Ruby Open-URI library aborted in 404 HTTP error code
I use OpenURI library.
object = open("http://example.com")
If http://example.com server code response is equals to 200 my program acts as I expected.
But if http://example.com server response code is equals to 400 (or other) then script aborts…

Sergey Blohin
- 600
- 1
- 4
- 31
7
votes
1 answer
Ruby Proxy Authentication GET/POST with OpenURI or net/http
I'm using ruby 1.9.3 and trying to use open-uri to get a url and try posting using Net:HTTP
Im trying to use proxy authentication for both:
Trying to do a POST request with net/http:
require 'net/http'
require 'open-uri'
http =…

Tarang
- 75,157
- 39
- 215
- 276
6
votes
1 answer
How can you tell if an FTP file exists using ruby?
I'm trying to figure out the best and fastest way to tell if a file exists on an ftp server.
This is what I came up with...
def remote_exists?(idx)
#@file.rewind if @file.eof?
ftp = Net::FTP.new(FTP_SERVER)
ftp.login
begin
ftp.size(idx)
…

hadees
- 1,754
- 2
- 25
- 36
6
votes
3 answers
404 not found, but can access normally from web browser
I tried many URLs on this and they seem to be fine until I came across this particular one:
require 'rubygems'
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open("http://www.moxyst.com/fashion/men-clothing/underwear.html"))
puts…

iboss
- 456
- 6
- 18
6
votes
2 answers
Zlib::BufError when using progressbar/ruby-progressbar gem
I use the following Ruby snippet to download a 8.9MB file.
require 'open-uri'
require 'net/http'
require 'uri'
def http_download_no_progress_bar(uri, filename)
uri.open(read_timeout: 500) do |file|
open filename, 'w' do |io|
…

JJD
- 50,076
- 60
- 203
- 339
6
votes
1 answer
Does ruby open-uri HTTP Streaming throttle the download or save to a temp file?
I have a large CSV file on a server I'd like to download and process in chunks, without reading the whole thing into memory. After a bit of finagling I've come up with this:
require open-uri
open("http://example.com/#{LARGE_CSV_FILE}") do |file|
…

Gabe Durazo
- 1,789
- 2
- 19
- 27