sparqlwrapper
sparqlwrapper copied to clipboard
QueryBadFormed: A bad request has been sent to the endpoint
I am not understanding the source of this error. Here is a fully functional test code:
from SPARQLWrapper import SPARQLWrapper, JSON
endpoint = "http://dati.senato.it/sparql"
sparql = SPARQLWrapper(endpoint)
sparql.setReturnFormat(JSON)
# just a simple query only to debug
sparqlquery = "SELECT * WHERE {?s ?p ?o} LIMIT 1"
sparql.setQuery(sparqlquery)
ret = sparql.queryAndConvert()
which generates the following error message:
Exception has occurred: QueryBadFormed
QueryBadFormed: A bad request has been sent to the endpoint: probably the SPARQL query is badly formed.
Response:
b"Virtuoso 37000 Error SP030: SPARQL compiler, line 0: Invalid character in SPARQL expression at '%'\n\nSPARQL query:\ndefine sql:big-data-const 0 \n#output-format:application/sparql-results+json\nSELECT %2A WHERE %7B%3Fs %3Fp %3Fo%7D LIMIT 1"
urllib.error.HTTPError: HTTP Error 400: Bad Request
During handling of the above exception, another exception occurred:
File "/Users/bob/Documents/work/getnews/python test/misc/senato.py", line 18, in <module>
ret = sparql.queryAndConvert()
^^^^^^^^^^^^^^^^^^^^^^^^
SPARQLWrapper.SPARQLExceptions.QueryBadFormed: QueryBadFormed: A bad request has been sent to the endpoint: probably the SPARQL query is badly formed.
Response:
b"Virtuoso 37000 Error SP030: SPARQL compiler, line 0: Invalid character in SPARQL expression at '%'\n\nSPARQL query:\ndefine sql:big-data-const 0 \n#output-format:application/sparql-results+json\nSELECT %2A WHERE %7B%3Fs %3Fp %3Fo%7D LIMIT 1"
Environment:
MacOS Ventura
python 3.11.0 h559f36b_0_cpython conda-forge
sparqlwrapper 2.0.0 pyha770c72_0 conda-forge
remote Virtuoso endpoint: Virtuoso version 06.01.3127 on Linux (x86_64-unknown-linux-gnu), Single Server Edition