open-uri and proxies

P

Phil Tomson

I was trying to play with open-uri as shown on Whytheluckystiff's
What's Shiny and new in Ruby 1.8 article:

require 'open-uri'
require 'yaml'

open( "http://www.whytheluckystiff.net/why.yml" ) do |f|
feed = YAML::load( f )
end


But I'm behind a firewall and need to use a proxy to get out. Any way
to use proxies with open-uri?

Phil
 
B

Bermejo, Rodrigo

Phil:

you can try setting your proxy via Env variable.

export HTTP_PROXY=your.proxy.goes.here


I'm also behind a firewall, I tried it, the proxy was taken from the env var but I got the following error:

usr/local/bin/lib/ruby/1.8/open-uri.rb:143:in `open_loop': undefined method `proxy_open' for #<URI::Generic:0x200c61c0 URL:http-myproxy.com> (NoMethodError)
from /usr/local/bin/lib/ruby/1.8/open-uri.rb:105:in `open_uri'
from /usr/local/bin/lib/ruby/1.8/open-uri.rb:74:in `open'
from 2.rb:4

p "?"


-Ronnie.
 
P

Phil Tomson

I was trying to play with open-uri as shown on Whytheluckystiff's
What's Shiny and new in Ruby 1.8 article:

require 'open-uri'
require 'yaml'

open( "http://www.whytheluckystiff.net/why.yml" ) do |f|
feed = YAML::load( f )
end


But I'm behind a firewall and need to use a proxy to get out. Any way
to use proxies with open-uri?

Found the recipe, here it is if you need it:

open("http://www.ruby-lang.org",:proxy=>"http://your.proxy.here:8080") do |f|
f.each_line {|line| p line }
end


Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top