I have the following Ruby code:
require 'net/http'
require 'uri'
include Net
$DEBUG = 1
print "Enter a GitHub username: "
username = gets
puts "Username = #{username}" if $DEBUG == 1
source = HTTP.get(URI.parse("http://github.com/api/v2/xml/user/show/#{username}"))
puts source if $DEBUG == 1
Whenever I run it, I get the following error:
Exception `Errno::EAGAIN' at /usr/local/lib/ruby/1.9.1/net/protocol.rb:135 - Resource temporarily unavailable - read would block
Even though it works fine. Any ideas as to why this is happening and how to stop it happening?
Thanks in advance!
EDIT: Using htty, I was able to connect to the desired server and get the resource just fine without any errors.
My guess is that your use of the global
$DEBUGvariable is revealing a bug or undesired state in Net::Protocol. If you set$DEBUG = falseit goes away.At that point in the Net::Protocol code it’s trying to do a non_blocking read, and appears to be timing out.
Ruby uses the $DEBUG flag as part of the
-dmechanism. If you putputs $DEBUGin a script and run it you’ll see that variable toggle. Because it’s a global it’ll be visible in any code needing debugging so you, or the code’s author, can trigger extra-special verboseness to help debug things: