Ruby: Too Many Open Files @ Rb_Sysopen

Ruby: Too many open files @ rb_sysopen

  • EMFILE is too many files opened in your process.
  • ENFILE is too many files opened in the entire system.

So Errno::EMFILE is due to the ruby process opening too many files. This limit is probably set to the default 1024 can be seen with:

$ulimit -n
1024

Instead of:

$ulimit
unlimited

You can raise the limit using this method.

Cannot open file with Ruby Errno::ENOENT: No such file or directory @ rb_sysopen

File.open expects files to be on the disk, it doesn't work with remote files.

Instead you could do use Net::HTTP.get, which will return a string.

 url = URI('https://www.pocket-rocket.io/robots.txt')
Net::HTTP.get(url) # => "User-agent: *\nDisallow: /wp-admin/\nAllow: /wp-admin/admin-ajax.php\n"

No such file or directory @ rb_sysopen for external URL / Rails 6.11 / Ruby 3

open-uri used to (before Ruby 3.0) overwrite Kernel#open with its own version which also supports reading from external URLs rather than simply opening local files or running commands.

Mixing those two use-cases was quite dangerous and had the potential for serious vulnerabilities if the passed URL was not ensured to be safe everywhere (including third-party code using Kernel#open).

As such, this behavior to overwrite Kernel#open was deprecated in Ruby 2.7 and finally removed in Ruby 3.0. To open an external URL, you can use the following code instead:

URI.open("https://brandemia.org/sites/default/files/inline/images/firefox_logo.jpg")

No such file or directory @ rb_sysopen -

You have to ensure the file zipUpTest/1051687701.jpg exists relative to where the process was run, not where the program is saved.

For example, let's say your program is /home/taizo/program. If you're in /home/taizo and run ruby program then it will look for /home/taizo/zipUpTest/1051687701.jpg. If you're in /tmp and run ruby /home/taizo/program the program will look for /tmp/zipUpTest/1051687701.jpg.

Ruby Invalid argument @ rb_sysopen

Method :open you call belongs to Kernel class:

> method :open
=> #<Method: Object(Kernel)#open(*)>

I believe you want to call URI.open because you require open-uri gems.

page Nokogiri::HTML(URI.open(url))

Parsing remote csv file : No such file or directory @ rb_sysopen

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 => "dageismar+learner233@gmail.com",
:role => "CEO",
:tags => "sales,marketing",
:avatar_url => "http://res.cloudinary.com/dockcyr0z/image/upload/x3f65o5mepbdhi4fwvww99gjqr7p"
}
{
:first_name => "Gentil",
:last_name => "Keum",
:email => "dageismar+learner234@gmail.com",
: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



Related Topics



Leave a reply



Submit