require 'open-uri' => true irb(main):002:0> open("http://www.google....">

Open ("http://www.google.com"), but wget works

open failed:

irb(main):001:0> require 'open-uri' => true irb(main):002:0> open("http://www.google.com") RuntimeError: Non-HTTP proxy URI: from /usr/lib/ruby/1.8/open-uri.rb:203:in `open_http' from /usr/lib/ruby/1.8/open-uri.rb:616:in `buffer_open' from /usr/lib/ruby/1.8/open-uri.rb:164:in `open_loop' from /usr/lib/ruby/1.8/open-uri.rb:162:in `catch' from /usr/lib/ruby/1.8/open-uri.rb:162:in `open_loop' from /usr/lib/ruby/1.8/open-uri.rb:132:in `open_uri' from /usr/lib/ruby/1.8/open-uri.rb:518:in `open' from /usr/lib/ruby/1.8/open-uri.rb:30:in `open' from (irb):2 

But wget () works ...

 root@pierr-desktop :/work/web/yy# wget www.google.com --2010-11-14 20:00:39-- http://www.google.com/ Resolving www.google.com... 72.14.203.104, 72.14.203.99 Connecting to www.google.com|72.14.203.104|:80... connected. HTTP request sent, awaiting response... 302 Found ......... 2010-11-14 20:00:40 (47.7 KB/s) - `index.html' saved [9097] 

Do I need to configure a proxy server, but I do not know the correct proxy information.

+4
source share
2 answers

Open-URI selects a proxy server from the environment if it is installed there, or you can determine it when opening a connection or even disable the proxy server if it is installed in the environment:

 # The environment variables such as http_proxy, https_proxy and ftp_proxy # are in effect by default. :proxy => nil disables proxy. open("http://www.ruby-lang.org/en/raa.html", :proxy => nil) {|f| # ... } 

See Open-URI documentation

Also, your Ruby looks old: /usr/lib/ruby/1.8/ . Do ruby -v , and if it is at least 1.8.7, I would recommend installing RVM and then using it to install the current Ruby (1.9.2) or at least the latest version 1.8 (1.8.7). Check the RVM Prerequisites , then follow the instructions, including the parts on changing the startup of your script account, and then read the part on installing Ruby gems .

I do not recommend using packaged Ruby through yum or apt. They are not going to be the last, and it seems that they lack all the creature comforts that we expect from installing Ruby source material. RVM simplifies installation and management of multiple rubies.

+5
source

If you have proxy settings specific to your system, you can check it using:

1- Check the configuration parameter /etc/wgetrc for http_proxy :

2- Check the environment variable using: echo $HTTP_PROXY

+1
source

All Articles