Reputation: 15604
The test code below of the pyLoDStorage project (of which i am a committer) used to work fine until i started working on https://github.com/WolfgangFahl/pyLoDStorage/issues/123 to upgrade Jena from 3.17.0 to 4.9.0 in the test environment.
I get the exception Exception: HTTP Error 415: Unsupported Media Type.
How could this problem be fixed?
Since i am using SparlWrapper Version 2.0.0 the media type is set to application/sparql-update
if self.method != POST:
warnings.warn("update operations MUST be done by POST")
if self.requestMethod == POSTDIRECTLY:
request = urllib.request.Request(
uri + "?" + self._getRequestEncodedParameters()
)
request.add_header("Content-Type", "application/sparql-update")
request.data = self.queryString.encode("UTF-8")
def testJenaInsert(self):
"""
test a Jena INSERT DATA
"""
jena = self.getJena(mode="update")
insertCommands = [
"""
PREFIX cr: <http://cr.bitplan.com/>
INSERT DATA {
cr:version cr:author "Wolfgang Fahl".
}
""",
"INVALID COMMAND",
]
for index, insertCommand in enumerate(insertCommands):
if index != 0:
warnings.simplefilter("ignore")
result, ex = jena.insert(insertCommand)
if index == 0:
if ex:
print(f"Exception: {ex}")
self.assertTrue(ex is None)
if self.debug:
print(result)
else:
msg = ex.args[0]
if self.debug:
print(msg)
self.assertTrue("QueryBadFormed" in msg)
# self.assertTrue("Error 400" in msg)
pass
Upvotes: 0
Views: 44
Reputation: 31
The way how Jena processes a received update query seems to have changed.
To get the QueryBadFormed error as before the query needs to be parsable as an SPARQL update query. Changing the query from INVALID COMMAND
to INSERT DATA { INVALID COMMAND }
solves the issue.
From the SPARQL 1.1 Graph Store HTTP Protocol: "If a clients issues a POST or PUT with a content type that is not understood by the graph store, the implementation MUST respond with 415 Unsupported Media Type."
Also the Jena server must have updates enabled to allow the SPARQL update queries.
Upvotes: 1