Replies: 5 comments
-
A fair question. Section 7 of the HTTP 1.1 spec [1] i) declares Content-Type as a header that SHOULD be emitted and ii) offers the client a chance to calculate the media type ("MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource"), with the instruction that "application/octet-stream" SHOULD be used as a fallback if no media type can be guessed. But it looks like Real Work(tm) will be required in this particular case: >>> mimetypes.guess_type('http://sw.opencyc.org/2009/04/07/concept/en/_http___dbpedia_org_ontology_PokerPlayer_')
(None, None) We should arrange matters so that RDFLib emits a more informative exception message, "AttributeError: 'NoneType' object has no attribute 'split'" falls well short of "No Content-Type header, refusing to guess", for example. There might be an argument for just bailing out: using "application/octet-stream" as the media type and registering that media type against the RDFLib XML parser as a kind of "best we can do in the circumstances" approach. It's a fix in this particular instance but I don't have any kind of a feel for what media type is actually typically served in the absence of a Content-Type header. But this approach, apart from just papering over the cracks, is both arbitrary and "magical", neither of which are good ideas when consuming graph content. I'm inclined to believe that RDFLib should simply raise an informative exception. (For the benefit of future seekers of enlightenment) - your code example contains all the elements of a workaround: >>> import rdflib
>>> import requests
>>> resp = requests.get('http://sw.opencyc.org/2009/04/07/concept/en/_http___dbpedia_org_ontology_PokerPlayer_')
>>> g = rdflib.Graph()
>>> g.parse(data=resp.content, format="xml")
<Graph identifier=Nd4a95afa438444babea2cc5c368a34d1 (<class 'rdflib.graph.Graph'>)> [1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html HTH |
Beta Was this translation helpful? Give feedback.
-
That's a good idea! Even if RDFLib developers refuse to implement "smart" parsers that consider such cases, i could handle this particular exception and workaround it myself. |
Beta Was this translation helpful? Give feedback.
-
You've pretty much accurately summarised RDFLib's approach to its users. RDFLib is a library not an application, so give users the relevant information, at the appropriate level of detail and allow them space to develop their own solutions to the inevitable wrinkles that appear. Just a small point of information: "refusing to guess" != "refuse to implement". The latter seems a little harsh and my off-the-cuff exception message may have given the wrong impression. All of the RDFLib dev team have very strong professional and personal demands on their time, so people do what they can, when they can. This has recently included some outstanding contributions: Gunnar's SPARQL 1.1 algebra implementation, Ivans RDF/A 1.1 parser implementation, Niklas' JSON-LD implementation, all of which are significant pieces of high-level work. In my case, I need to eat this month :-) HTH |
Beta Was this translation helpful? Give feedback.
-
Oh, i didn't want to sound mean at all. The developers could refuse for various fair reasons. I think the best solution currently is to provide meaningful errors and document all possible corner cases in manuals. Then the programmer that uses RDFLib would be given example workarounds. Something like:
|
Beta Was this translation helpful? Give feedback.
-
Some URLs don't return Content-type in accept headers:
Should
Graph.parse
account for such cases? The URL itself returns valid RDF/XML.Beta Was this translation helpful? Give feedback.
All reactions