Python3.8 rdflib utf-8 problems SPARQLSTORE

I am using rdflib and SPARQLStore

store2 = SPARQLUpdateStore(query_endpoint=SPARQL_URI, update_endpoint=SPARQL_UPDATE_URI,
auth=auth, context_aware=True,
postAsEncoded=False)

bg =rdflib.Graph(store=store2, identifier="http://test.graph")
bg.add((rdflib.URIRef("http://TEST"),rdflib.RDFS["label"],rdflib.Literal("MÜRIzü"))

If I query this I get:

for x in bg.query("select * where {http://TEST ?x ?y.}"):
print(x)

(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'), rdflib.term.Literal('MÃ\x9cRIzü'))

What can I do?

Reply to my own, account I had to overwrite the updat method of SPARQLConnector to explicitly set utf-8 in the header. Is this really the only solution?

def update(
self,
query,
default_graph: Optional[str] = None,
named_graph: Optional[str] = None,
):
if not self.update_endpoint:
raise SPARQLConnectorException("Query endpoint not set!")

    params = {}

    if default_graph is not None:
        params["using-graph-uri"] = default_graph

    if named_graph is not None:
        params["using-named-graph-uri"] = named_graph

    headers = {
        "Accept": _response_mime_types[self.returnFormat],
        "Content-Type": "application/sparql-update; charset=UTF-8",
    }

    args = dict(self.kwargs)  # other QSAs

    args.setdefault("params", {})
    args["params"].update(params)
    args.setdefault("headers", {})
    args["headers"].update(headers)

    qsa = "?" + urlencode(args["params"])
    res = urlopen(
        Request(
            self.update_endpoint + qsa, data=query.encode(), headers=args["headers"]
        )
    )

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.