问题描述
我一直试图让SPARQLWrapper插入一个简单的三元组到GraphDB中,但没有成功.我选择查询没有问题.这是失败的Python测试代码:
I've been trying to get SPARQLWrapper to insert a simple triple into GraphDB with no success. I have no trouble with select queries. Here's Python test code that fails:
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'缺少参数:查询'
Response: b'Missing parameter: query'
我到处都看过,尝试了所有建议的内容,但无法正常工作.感谢任何好的线索.
I've looked everywhere and tried everything suggested and can't get it to work. Grateful for any good leads.
请参阅我对查询验证添加的评论.问题是重复的并且已经回答的建议不适用.
See my added comment on validation of the query. The suggestion that the question is a duplicate and already answered is not applicable.
推荐答案
GraphDB公开了芝麻样式终结点URL.
下面是GraphDB 8.3 Workbench帮助页面的屏幕截图(我正在使用Free Edition).
GraphDB exposes Sesame-style endpoint URLs.
Here below a screenshot of GraphDB 8.3 Workbench help page (I'm using Free Edition).
以下Python代码对我有用(repositoryID
是wikidata
):
The following Python code works for me (repositoryID
is 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()
这篇关于无法使INSERT在SPARQLWrapper中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!