Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4625122
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:13:38+00:00 2026-05-22T03:13:38+00:00

I am looking for a way to read and parse locally a remote CSV

  • 0

I am looking for a way to read and parse locally a remote CSV (hosted on a particular website).

I found on the Internet a couple of interesting examples that make use of FasterCSV, that in ruby 1.9.2 has been merged into CSV. I found that you can read a remote CSV using the gems ‘csv’ and ‘open-uri’ this way:

require 'csv'
require 'open-uri'

def read(url)
  open(url) do |f|
    f.each_line do |l|
      CSV.parse(l) do |row|
        puts row
      end
    end
  end
end

But when I call this function, I get an exception:

ERROR IOError: closed stream

Anyone can explain me why? Is there anything wrong? Should I choose another approach for reading remote CSV’s?

Update

The best solution I’ve found till now is this:

def read(url)
  data = []
  begin
    open(url) do |f|
      data = CSV.parse f
    end
  rescue IOError => e
    # Silently catch the exception ...
  end

  return data
end

but it somewhat seems not so clean. I really do not like silently catching an exception where it shouldn’t be …

Update 2

I can reproduce the error using both

ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]

and

ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]

This is the code from my test.rb file:

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

def read(url)
  data = []
  begin
    open(url) do |f|
      data = CSV.parse f
    end
  end

  puts data
end

read("http://www.euribor-ebf.eu/assets/modules/rateisblue/processed_files/myav_EURIBOR_2011.csv")

And this is the output of the ruby test.rb command

/Users/marzu/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:152:in `close': closed stream (IOError)
from /Users/marzu/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:152:in `open_uri'
from /Users/marzu/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:671:in `open'
from /Users/marzu/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/open-uri.rb:33:in `open'
from test.rb:8:in `read'
from test.rb:16:in `<main>'

I am using rvm 1.6.9 on Mac OS X 10.6.7.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:13:38+00:00Added an answer on May 22, 2026 at 3:13 am

    On Mac OS X 10.6.7, using ruby r1.9.2, I get the same error as displayed above. But using the following code to read CSV files works for the example URL provided:

    require 'rubygems'
    require 'open-uri'
    require 'csv'
    
    def read(url)
     CSV.new(open(url), :headers => :first_row).each do |line|
       puts line
       puts line[0]
       puts line['FEB11']
     end
    end
    
    read("http://www.euribor-ebf.eu/assets/modules/rateisblue/processed_files/myav_EURIBOR_2011.csv")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

looking for a way to read arguments from a configuration file I found a
I am looking for a way to parse just a particular part of a
I'm looking for a fast and reliable way to read/parse large PDF files in
I am looking to see a simple way to read from and write to
I'm looking for a way if you know the location where to read the
Please note - I am not looking for the right way to open/read a
I'm looking for a faster way to calculate GC content for DNA strings read
I'm looking a way to enable IP logging with log4net in ASP.NET. I found
Is there a default/official/recommended way to parse CSV files in C#? I don't want
I'm looking for an easy and safe way to parse a map, and only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.