[ruby-list:48871] Re: [質問] /usr/lib/ruby/1.8/net/http.rb:560:in `initialize': getaddrinfo: Name or service not known (SocketError)
From:
Tomoyuki Chikanaga <nagachika00@...>
Date:
2012-08-07 01:06:02 UTC
List:
ruby-list #48871
近永と申します。
Machanize には詳しくないのですが, ドキュメントによると proxy の設定は
ようにコードで設定しなければならず、環境変数は使っていないようです。
http://mechanize.rubyforge.org/Mechanize/HTTP/Agent.html#method-i-proxy_uri
試せていませんがこんなふうにするとどうでしょうか?
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
agent.set_proxy("proxy.company.co.jp", 10080)
page = agent.get('http://google.com/')
以上です。
2012年8月7日 9:53 Takahiro Yamaguchi <Takahiro.Yamaguchi@jp.sony.com>:
>
> 山口と申します。
>
> yama@roswell:~/tmp$ uname -a
> Linux roswell 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:50:42 UTC 2011 i686 i686 i386 GNU/Linux
> yama@roswell:~/tmp$ ruby --version
> ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
>
> の環境で、mechanize v2.5.1-9 GUIDE.rdocに記載されている
> == Let's Fetch a Page! のサンプルコード
>
> yama@roswell:~/tmp$ cat Google.rb
> require 'rubygems'
> require 'mechanize'
>
> agent = Mechanize.new
> page = agent.get('http://google.com/')
>
> を、動作させたところ、
>
> yama@roswell:~/tmp$ ruby Google.rb
> /usr/lib/ruby/1.8/net/http.rb:560:in `initialize': getaddrinfo: Name or service not known (SocketError)
> from /usr/lib/ruby/1.8/net/http.rb:560:in `open'
> from /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
> from /usr/lib/ruby/1.8/timeout.rb:53:in `timeout'
> from /usr/lib/ruby/1.8/timeout.rb:101:in `timeout'
> from /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
> from /usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
> from /usr/lib/ruby/1.8/net/http.rb:548:in `start'
> from /usr/lib/ruby/1.8/mechanize.rb:527:in `fetch_page'
> from /usr/lib/ruby/1.8/mechanize.rb:259:in `get'
> from Google.rb:5
>
> となり、動作しません。
>
> 社内からのアクセスのため、proxyの設定を忘れていたので、
> http://d.hatena.ne.jp/takatoh/20070522/http_proxy
> を参考に、
>
> yama@roswell:~/tmp$ export HTTP_PROXY=http://proxy.company.co.jp:10080/
> yama@roswell:~/tmp$ ruby Google.rb
> /usr/lib/ruby/1.8/net/http.rb:560:in `initialize': getaddrinfo: Name or service not known (SocketError)
> ...
> yama@roswell:~/tmp$ export HTTP_PROXY=http://proxy.company.co.jp:10080
> yama@roswell:~/tmp$ ruby Google.rb
> /usr/lib/ruby/1.8/net/http.rb:560:in `initialize': getaddrinfo: Name or service not known (SocketError)
> ...
> yama@roswell:~/tmp$ set http_proxy=http://proxy.company.co.jp:10080/
> yama@roswell:~/tmp$ ruby Google.rb
> /usr/lib/ruby/1.8/net/http.rb:560:in `initialize': getaddrinfo: Name or service not known (SocketError)
> ...
>
> いろいろ試みましたが、症状は変わらずです。
>
> 解決策をご教示いただけないでしょうか?
> よろしくお願いします。
>
> ちなみに、wget は正しく動作する環境です。
>
> yama@roswell:/tmp$ wget http://www.google.com
> --2012-08-07 09:45:39-- http://www.google.com/
> proxy.company.co.jp をDNSに問いあわせています... aaaa:bbb:0:161::14, ccc.ddd.66.14
> proxy.company.co.jp|aaaa:bbb:0:161::14|:10080 に接続しています... 接続しました。
> Proxy による接続要求を送信しました、応答を待っています... 302 Found
> 場所: http://www.google.co.jp/ [続く]
> --2012-08-07 09:45:39-- http://www.google.co.jp/
> proxy.company.co.jp|aaaa:bbb:0:161::14|:10080 に接続しています... 接続しました。
> Proxy による接続要求を送信しました、応答を待っています... 200 OK
> 長さ: 特定できません [text/html]
> `index.html.1' に保存中
>
> [ <=> ] 13,403 --.-K/s 時間 0.004s
>
> 2012-08-07 09:45:39 (2.86 MB/s) - `index.html.1' へ保存終了 [13403]
>
> --
> Takahiro Yamaguchi
>