You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 maybe results or output. 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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: