From: ara.t.howard@... Date: 2006-06-28T05:50:43+09:00 Subject: Re: URI::InvalidURIError when using curly brackets On Wed, 28 Jun 2006, Richard Leonard wrote: > I've been experimenting using open-uri to retrieve HTML from various > sites and have spent the past couple of days searching for an answer to > my problem. One page I've been trying to access contains a GUID in the > querystring and it has curly brackets around it. This is my code (I'm > just using Google for this example): > > require 'open-uri' > > uri = > URI.parse('http://www.google.co.uk/search?q={3F2504E0-4F89-11D3-9A-0C-03-05-E8-2C-33-01}') > html = open(uri).read() > > But I get the following error: > > URI::InvalidURIError in DemoController#index > > bad URI(is not URI?): > http://www.google.co.uk/search?q={3F2504E0-4F89-11D3-9A-0C-03-05-E8-2C-33-01} > > RAILS_ROOT: /code/public/../config/.. > > /usr/local/lib/ruby/1.8/uri/common.rb:432:in `split' > /usr/local/lib/ruby/1.8/uri/common.rb:481:in `parse' > #{RAILS_ROOT}/app/controllers/scrape_controller.rb:10:in `index' > >> From what I've found, curly brackets aren't allowed in a Ruby URI > (despite my browser being capable of handling them). I've tried encoding > them with %7B and %7D but then the page is called with the encoded > version, which in my case, the site isn't expecting and it doesn't work. > > Is there a way to allow curly brackets in my URI? or another method to > download HTML which does? > > Thanks. irb(main):001:0> URI.parse(URI.encode("http://www.google.co.uk/search?q={3F2504E0-4F89-11D3-9A-0C-03-05-E8-2C-33-01}")) => # -a -- suffering increases your inner strength. also, the wishing for suffering makes the suffering disappear. - h.h. the 14th dali lama