我目前正在編寫一個腳本,它遍歷URL列表並對它們執行一些處理。然而,我列表中的一個URL給我一個問題。代碼如下:使用Ruby發出HTTP請求時發生EOF錯誤
url = "https://secure.www.alumniconnections.com/olc/pub/CDB/events/attendance.cgi? tmpl=attendance&event=2309515&sort=4"
uri = URI.parse(url)
response = Net::HTTP.get_response(uri)
最後一行引發以下錯誤:
EOFError: end of file reached
from /usr/lib/ruby/1.8/net/protocol.rb:135:in `sysread'
from /usr/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'
from /usr/lib/ruby/1.8/timeout.rb:67:in `timeout'
from /usr/lib/ruby/1.8/timeout.rb:101:in `timeout'
from /usr/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
from /usr/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
from /usr/lib/ruby/1.8/net/protocol.rb:126:in `readline'
from /usr/lib/ruby/1.8/net/http.rb:2028:in `read_status_line'
from /usr/lib/ruby/1.8/net/http.rb:2017:in `read_new'
from /usr/lib/ruby/1.8/net/http.rb:1051:in `request'
from /usr/lib/ruby/1.8/net/http.rb:948:in `request_get'
from /usr/lib/ruby/1.8/net/http.rb:380:in `get_response'
from /usr/lib/ruby/1.8/net/http.rb:543:in `start'
from /usr/lib/ruby/1.8/net/http.rb:379:in `get_response'
from (irb):5
from /usr/lib/ruby/1.8/uri/ftp.rb:190
在我的名單沒有其他網址似乎是給我任何的悲傷。任何人都可以解釋爲什麼我得到這個錯誤?
您的第一個片段可能導致無限循環嗎? –
是的,我相信可以。不知何故,我從來沒有抓到過。我會做一個快速修改來解決,儘管我不能保證它會是最好的解決方案。 – scradge