解析远程CSV文件:无此类文件或目录 @ rb_sysopen

发布于 2025-02-08 19:32:21 字数 725 浏览 0 评论 0 原文

我正在尝试解析托管托管的CSV文件。我的用户导轨6和主动存储。该文件存储在ImportJob模型上。可以通过这种方式访问​​其URL:

ImportJob.last.csv_file.url

该文件确实存在并且可下载:

However when trying to parse it

CSV.foreach(url, headers: true, header_converters: :symbol, col_sep: ';') do |row|
 puts row
end

Im getting Errno::ENOENT: No such file or directory @ rb_sysopen - http://res .cloudinary.com/dockcyr0z/raw/upload/rghn3zi2190nmc28qwbtr24apqxe.csv

如果我尝试先打开文件: open(url)

我为什么会遇到这个错误?如何解析此远程CSV文件?

I am trying to parse a csv file hosted remotely. I user rails 6 and active storage. The file is stored on the ImportJob model. Its url can be accessed this way :

ImportJob.last.csv_file.url

the file does exist and is downloadable : http://res.cloudinary.com/dockcyr0z/raw/upload/rghn3zi2190nmc28qwbtr24apqxe.csv

However when trying to parse it

CSV.foreach(url, headers: true, header_converters: :symbol, col_sep: ';') do |row|
 puts row
end

Im getting Errno::ENOENT: No such file or directory @ rb_sysopen - http://res.cloudinary.com/dockcyr0z/raw/upload/rghn3zi2190nmc28qwbtr24apqxe.csv

same thing if I try to open the file first : open(url)

Why am I getting this error ? How can I parse this remote csv file ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聽兲甴掵 2025-02-15 19:32:21

打开 url 带有 uri.parse 和更改 csv.foreach to csv.parse

CSV.parse(URI.parse(url).read, headers: true, header_converters: :symbol, col_sep: ';') do |row|
  puts row
end
# output

{
    :first_name => "Souper",
     :last_name => "Man",
         :email => "[email protected]",
          :role => "CEO",
          :tags => "sales,marketing",
    :avatar_url => "http://res.cloudinary.com/dockcyr0z/image/upload/x3f65o5mepbdhi4fwvww99gjqr7p"
}
{
    :first_name => "Gentil",
     :last_name => "Keum",
         :email => "[email protected]",
          :role => "CEO",
          :tags => "sales,marketing",
    :avatar_url => "http://res.cloudinary.com/dockcyr0z/image/upload/x3f65o5mepbdhi4fwvww99gjqr7p"
}

更新

或AS Stefan 建议只建议 uri.open(url)而不是 uri .parse(url).Read

Open url with URI.parse and change CSV.foreach to CSV.parse

CSV.parse(URI.parse(url).read, headers: true, header_converters: :symbol, col_sep: ';') do |row|
  puts row
end
# output

{
    :first_name => "Souper",
     :last_name => "Man",
         :email => "[email protected]",
          :role => "CEO",
          :tags => "sales,marketing",
    :avatar_url => "http://res.cloudinary.com/dockcyr0z/image/upload/x3f65o5mepbdhi4fwvww99gjqr7p"
}
{
    :first_name => "Gentil",
     :last_name => "Keum",
         :email => "[email protected]",
          :role => "CEO",
          :tags => "sales,marketing",
    :avatar_url => "http://res.cloudinary.com/dockcyr0z/image/upload/x3f65o5mepbdhi4fwvww99gjqr7p"
}

Update:

Or as Stefan suggests just URI.open(url) instead of URI.parse(url).read

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文