0

SPARQLWRapper provides us a user-friendly interface for issuing SPARQL queries, for example, you can execute a SPARQL query simply with the following two lines of code.

sparql.setQuery(query)
results = sparql.query().convert()

However, one thing I notice is that, sometimes the query might crash the sparql endpoint, however, sparql.query().convert() does not raise any exception, it just returns an empty set as answer. And for the next query, because the sparql endpoint was crashed by the previous query, it will report connection refused. This reported error does not really help us to know what the real problem is; what we do want to know is what is happening when the server is crashed. I expect sparql.query().convert() to raise some exception if the sparql endpoint is crashed during processing it, but unfortunately, it does not. So is there any way for me to catch such exception when using SPARQLWrapper?

Yu Gu
  • 2,382
  • 5
  • 18
  • 33
  • First thing to check is whether the endpoint returns an error at all. In HTTP, status code comes first so "send 200, start executing query, send a few results, goes wrong" can't be signalled by the HTTP status code. (Alternative is buffer whole response so know the status code but that can be costly at the server.) – AndyS Dec 30 '20 at 10:05
  • @AndyS yeah I think I should check whether an error was returned by the endpoint. But I am not sure where to retrieve that error code, maybe it's hardcoded somewhere inside the `convert` method of SPARQLWrapper. – Yu Gu Dec 31 '20 at 02:02
  • `SPARQLWrapper` does raise exceptions already for the `query()` method: https://sparqlwrapper.readthedocs.io/en/latest/SPARQLWrapper.Wrapper.html#SPARQLWrapper.Wrapper.SPARQLWrapper._query - also other people have been asking how to get more details from the exception, see https://stackoverflow.com/questions/63486767/how-can-i-get-the-fuseki-api-via-sparqlwrapper-to-properly-report-a-detailed-err or https://github.com/RDFLib/sparqlwrapper/issues/161 – UninformedUser Dec 31 '20 at 06:51

0 Answers0