我一直试图让SPARQLWrapper将一个简单的三元组插入到GraphDB中,但没有成功。我对select查询没有问题。下面是失败的Python测试代码:
db = sparqlw.SPARQLWrapper(endpoint)
query = '''
INSERT {<http://example.com/123456789876> a owl:Thing .}
WHERE {}
'''
db.setQuery(query)
db.method = sparqlw.POST
db.setReturnFormat(sparqlw.JSON)
db.queryType= sparqlw.INSERT
result = db.query()它返回以下错误:
"urllib.error.HTTPError: HTTP Error 400: Bad Request"和
"SPARQLWrapper.SPARQLExceptions.QueryBadFormed: QueryBadFormed: a bad
request has been sent to the endpoint, probably the sparql query is bad
formed."响应:B‘错误参数:查询’
我到处都找过了,试过了所有建议的东西,但都不能让它起作用。感谢任何好的线索。
请参阅我添加的关于查询验证的注释。关于这个问题是重复的并且已经回答的建议是不适用的。
发布于 2017-09-18 16:07:22
GraphDB公开芝麻式端点URL。
下面是GraphDB 8.3工作台帮助页面的截图(我使用的是免费版)。

下面的Python代码适用于我(repositoryID是wikidata):
from SPARQLWrapper import SPARQLWrapper, BASIC
db = SPARQLWrapper("http://localhost:7200/repositories/wikidata/statements")
query = '''
INSERT {<http://example.com/123456789879> a owl:Thing .}
WHERE {}
'''
db.setHTTPAuth(BASIC)
db.setCredentials('login', 'password')
db.setQuery(query)
db.method = "POST"
db.setReturnFormat('json')
db.queryType = "INSERT"
result = db.query()https://stackoverflow.com/questions/46271187
复制相似问题