gpt4 book ai didi

ruby - `sysread' : end of file reached (EOFError)

转载 作者:太空宇宙 更新时间:2023-11-03 16:48:23 25 4
gpt4 key购买 nike

require 'net/http'
require 'uri'
Net::HTTP.get_print URI.parse('https://forums.malwarebytes.org/index.php?showtopic=49893')

我收到如下错误:c:/ruby/lib/ruby/1.8/net/protocol.rb:133:in sysread': 到达文件末尾 (EOFError)
来自 c:/ruby/lib/ruby/1.8/net/protocol.rb:133:in
rbuf_fill' 来自 c:/ruby/lib/ruby/1.8/timeout.rb:56:in timeout'
来自 c:/ruby/lib/ruby/1.8/timeout.rb:76:in
timeout' 来自 c:/ruby/lib/ruby/1.8/net/protocol.rb:132:in rbuf_fill'
来自 c:/ruby/lib/ruby/1.8/net/protocol.rb:116:in
readuntil' 来自 c:/ruby/lib/ruby/1.8/net/protocol.rb:126:in readline'
来自 c:/ruby/lib/ruby/1.8/net/http.rb:2029:in
read_status_line' 来自 c:/ruby/lib/ruby/1.8/net/http.rb:2018:in read_new'
来自 c:/ruby/lib/ruby/1.8/net/http.rb:1059:in
request' 来自 c:/ruby/lib/ruby/1.8/net/http.rb:957:in request_get'
来自 c:/ruby/lib/ruby/1.8/net/http.rb:380:in
get_response' 来自 c:/ruby/lib/ruby/1.8/net/http.rb:547:in start'
来自 c:/ruby/lib/ruby/1.8/net/http.rb:379:in
get_response' 来自 c:/ruby/lib/ruby/1.8/net/http.rb:337:in `get_print' 来自 urlparsing1.rb:3

最佳答案

我无法在现代 ruby​​ 版本上重现上述行为,但我想我知道是什么原因造成的。

让我们逐步深入了解执行过程:

▶ u = URI.parse('https://forums.malwarebytes.org/index.php?showtopic=49893')
#⇒ #<URI::HTTPS https://forums.malwarebytes.org/index.php?showtopic=49893>

好的,URI 得到了。

▶ Net::HTTP.get_print u
#⇒ <html><head><meta http-equiv='refresh' content='0;
# url=/index.php?/topic/49893-removal-instructions-for-a-fast-antivirus/'>
# </head><body></body></html>=> nil

糟糕。重定向。让我们来处理它:

▶ u_redir = Net::HTTP.get(u).scan(/url=(.*?)'/).first.first
#⇒ "/index.php?/topic/49893-removal-instructions-for-a-fast-antivirus/"

▶ u.path, u.query = u_redir.split '?'
#⇒ [
# [0] "/index.php",
# [1] "/topic/49893-removal-instructions-for-a-fast-antivirus/"
# ]
▶ Net::HTTP.get_print u
#⇒ [HTML CONTENT]

总结:我猜你应该自己处理重定向。

关于ruby - `sysread' : end of file reached (EOFError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28425044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com