Issue #11322 has been updated by D.E. Akers.


The problem is not specific to `OpenURI`:

    $ curl -L http://apps.london.ca/OpenData/ShapeFiles_Zipped/2010_skateboard_parks_shp.zip
    curl: (47) Maximum (50) redirects followed

It seems the `302 Object Moved` handler on this server has not been properly configured; it expects the previous request to have set a few cookies and simply sends the client back if it doesn't find them.

`OpenURI` appears to be incapable of handling such a circumstance, but `Net::HTTP` can and isn't that much more complex. I've presented below a demonstration of how you might go about orchestrating the "handshake" in order to successfully obtain the file.

``` ruby
conn = Net::HTTP.new 'apps.london.ca'
file = '/OpenData/ShapeFiles_Zipped/2010_skateboard_parks_shp.zip'
resp = conn.get file

cookie = resp.get_fields('Set-Cookie').map { |c| c.split(';')[0] }.join(';')
resp   = conn.get file, 'Cookie' => cookie
File.write File.basename(file), resp.body
```

----------------------------------------
Bug #11322: OpenUri: RuntimeError: HTTP redirection loop
https://bugs.ruby-lang.org/issues/11322#change-53229

* Author: Tobias Preuss
* Status: Open
* Priority: Normal
* Assignee: Akira Tanaka
* ruby -v: ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Trying to download [this file](http://apps.london.ca/OpenData/ShapeFiles_Zipped/2010_skateboard_parks_shp.zip) from [this website](http://www.london.ca/city-hall/open-data/Pages/Open-Data-Data-Catalogue.aspx) with [`OpenUri`](http://ruby-doc.org/stdlib-2.2.2/libdoc/open-uri/rdoc/OpenURI.html) fails with the runtime error "HTTP redirection loop".
Here is how I can reproduce the error:

~~~
> require 'open-uri'
 => true

> open('http://apps.london.ca/OpenData/ShapeFiles_Zipped/2010_skateboard_parks_shp.zip')
RuntimeError: HTTP redirection loop: http://apps.london.ca/uniquesig87fdc01fb86ce6f0fd235c713015d7d7/uniquesig0/InternalSite/StartApp.asp?resource_id=837A134B9EC24A2197B6AF5745B6CA55&login_type=0&site_name=appstrunk&secure=0&orig_url=http%3a%2f%2fapps.london.ca%2fOpenData%2fShapeFiles_Zipped%2f2010_skateboard_parks_shp.zip
	from /home/john/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/open-uri.rb:232:in `open_loop'
	from /home/john/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/open-uri.rb:150:in `open_uri'
	from /home/john/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/open-uri.rb:716:in `open'
	from /home/john/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/open-uri.rb:34:in `open'
	from (irb):2
	from /home/john/.rvm/rubies/ruby-2.2.2/bin/irb:11:in `<main>'
~~~



-- 
https://bugs.ruby-lang.org/