Nokogiriを使用してオンラインxmlドキュメントからいくつかの気象データを取得しています。ソースに到達できない場合に備えて、正常な回復のためのタイムアウトを設定したいと思います...
私のグーグル検索はopen-uriとNet::HTTPのいくつかの可能な方法を示していますが、Nokogiriに固有のものはありません。これらの方法を使用する私の試みは失敗しています(それほど驚くことではありません):
begin
currentloc = ("http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=" + @destination.weatherloc)
currentloc.read_timeout = 10 #
doc = Nokogiri::XML(open(currentloc))
rescue Timeout::Error
return "Current weather for this location not available: request timed out."
end
「NoMethodError」を返し、次のようになります。
begin
currentloc = ("http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=" + @destination.weatherloc)
doc = Nokogiri::XML(open(currentloc), :read_timeout => 10)
rescue Timeout::Error
return "Current weather for this location not available: request timed out."
end
「TypeErrorはハッシュを文字列に変換できません」を返します
Nokogiriはこの種の方法をサポートしていますか(もしそうなら...どのように?)、または他の解決策を検討する必要がありますか?
ありがとう。