OpenURI::HTTPError: 406 Unacceptable #107

Closed
Robino opened this Issue Mar 10, 2013 · 3 comments

Comments

Projects
None yet
2 participants

Robino commented Mar 10, 2013

My code produces the error "OpenURI::HTTPError: 406 Unacceptable":

require 'rdf'
require 'linkeddata'
graph = RDF::Graph.load("http://dbpedia.org/resource/Elvis_Presley")

But if I load another graph from "bestbuy" than "Elvis", now "Elvis" graph works without error:

require 'rdf'
require 'linkeddata'
graph = RDF::Graph.load("http://www.bestbuy.com/shop/ipad+xoom+-windows")
graph = RDF::Graph.load("http://dbpedia.org/resource/Elvis_Presley")
graph.size
=> >2000

Owner

gkellogg commented Mar 10, 2013

Seems like it could be a content-negotiation issue. I should probably update the default Accept header to include a low-priority /. I believe you can add accept headers in the graph.load; check options to Util::File#open_file.

I'll look at if further when I'm at a computer.

@ghost ghost assigned gkellogg Mar 10, 2013

Robino commented Mar 10, 2013

Hello,

Yes you're right. I add in the file until/file.rb at the line 39 : "application/json" and it works fine now.
options[:headers]['Accept'] ||= RDF::Reader.map {|r| r.format.content_type}.uniq.join(", ") + "application/json"

I check and by default using graph.load, formats accepted are : "application/n-triples, text/plain, text/x-nquads"
I know that my change is not good, but I don't know what to modify.

Owner

gkellogg commented Mar 10, 2013

I think the problem is that RDF::Reader.map only returns loaded readers, and unless you've done something else, this won't include RDF::JSON. To solve your immediate problem, if you just access RDF::JSON::Reader when you start, that will be sure that reader is loaded, and cause it to add application/json to the Accept header.

I think the change probably needs to be the following:

options[:headers]['Accept'] ||=  RDF::Format.class_variable_get(:@@readers).keys.map(&:content_type).flatten.uniq

This is the only way to find the available readers, without loading them. It's probably worth defining a class method for this, and to find writer formats.

Also, this made me see that RDF::Format.reader_symbols ends up loading all readers, which is a bug.

gkellogg added a commit that referenced this issue Mar 20, 2013

Fixed Format.reader_symbols/writer_symbols to not load every reader/w…
…riter.

Added Format.reader_types/writer_types to get content types associated with available readers/writers.
Update File.open_file to use Format.reader_types
Include */*;q=0.1 as catch-all in Accept header.
This addresses issue #107

@gkellogg gkellogg closed this Mar 23, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment