Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Net::HTTP.get出现奇怪的Ruby错误_Ruby_Http - Fatal编程技术网

Net::HTTP.get出现奇怪的Ruby错误

Net::HTTP.get出现奇怪的Ruby错误,ruby,http,Ruby,Http,我有以下Ruby代码: 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}"))

我有以下Ruby代码:

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
无论何时运行,都会出现以下错误:

Exception `Errno::EAGAIN' at /usr/local/lib/ruby/1.9.1/net/protocol.rb:135 - Resource temporarily unavailable - read would block
尽管它工作得很好。关于为什么会发生这种情况以及如何阻止这种情况发生,有什么想法吗

提前谢谢


编辑:使用,我可以连接到所需的服务器,并获得没有任何错误的资源。

这是您的$DEBUG=1,如果未定义$DEBUG(或设置为false),则没有错误。Ruby解释器可能会在内部使用它,如果设置了它,它会打印出调试信息。

我猜您使用全局
$debug
变量揭示了Net::Protocol中的错误或不希望出现的状态。如果设置
$DEBUG=false
,它将消失

在Net::Protocol代码中,它试图进行非阻塞读取,并且似乎超时了

Ruby使用$DEBUG标志作为
-d
机制的一部分。如果在脚本中放入
并运行$DEBUG
,您将看到变量切换。因为它是全局的,所以它在任何需要调试的代码中都是可见的,所以您或代码的作者可以触发额外的详细信息来帮助调试:

greg-mbp-wireless:Desktop greg$ ruby untitled.rb 
false
greg-mbp-wireless:Desktop greg$ ruby -d untitled.rb 
true

你的代码对我来说就像Ruby 1.8.7/Linux一样有效