Open hendursaga opened 1 year ago
Indeed, the problem seems to be that format
parameter added by SPARQLWrapper. Fortunately the class comes with a method setOnlyConneg
to suppress these parameters and to rely on content negotiation only.
This seems to be the solution as this code snippet may demonstrate:
from SPARQLWrapper import SPARQLWrapper, CSV
sparql = SPARQLWrapper("https://query.wikidata.org/sparql", returnFormat=CSV)
sparql.setOnlyConneg(True) # enforce content negotiation only!
sparql.setQuery('SELECT * WHERE {?s ?p ?o} LIMIT 3')
ret = sparql.query()
ret._get_responseFormat() # -> 'csv'
While I can request WikiData to return JSON easily on SELECT queries, I cannot do the same for CSV/TSV, it just returns XML and then sparqlwrapper complains it's not in a format it's expecting.
I think the problem has to do with setting URL parameters like
format
and mayberesults
oroutput
. See this article and its referenced link.I'm not sure if that's correct behavior or not on WikiData's side, but it would be nice to have at least a workaround.