【发布时间】:2019-10-11 20:21:03
【问题描述】:
我正在尝试将数据插入 GraphDB,因此 SPARQL 更新查询由总大小约为 1M 的语句组成,其中包含一些 DELETE 和 WHERE 语句。 我使用 GraphDB REST API 失败了:
1) 成功启动交易 POST /repositories/{repositoryID}/transactions 2) 发送更新请求(python中的代码sn-p)
requests.put(
url='/repositories/{repositoryID}/transactions/{transactionID}'
params={'update': sparql, 'action': 'ADD'}
)
遇到错误
<!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1><hr class="line" /><p><b>Type</b> Exception Report</p><p><b>Message</b> Request header is too large</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><p><b>Exception</b></p><pre>java.lang.IllegalArgumentException: Request header is too large
此 sparql 语句在 Workbench SPARQL 控制台中成功执行。但是如果我增加我得到的数据数量
java.lang.StackOverflowError
在工作台 UI 中。
我要执行的sparql是以下
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX tr: <http://www.semanticweb.org/tr#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX geosparql: <http://www.opengis.net/ont/geosparql#>
DELETE { tr:ontologyVersion tr:hasTimestamp ?o . }
INSERT {
trip:ontologyVersion a time:Instant, owl:NamedIndividual ;
trip:hasTimestamp "2019-10-11 14:56:06.750130+00:00"^^xsd:dateTime .
<a lot of new triples>
}
WHERE {
OPTIONAL { tr:ontologyVersion tr:hasTimestamp ?o . }
}
那么如何将数据插入GraphDB,正确的做法是什么?
更新 1
我重写了代码来使用
requests.put(url=url, data={'update': sparql}, params={'action': 'COMMIT'})
并使用 sparql = "DELETE DATA {}; INSERT DATA {}"。请求已完成,响应代码为 200,但由于某些原因数据不在 GraphDB 中。
更新 2
根据The rdf4j server REST API我将请求改为
requests.put(url=transaction_url, data={'update': sparql}, params={'action': 'UPDATE'})
requests.put(url=transaction_url, params={'action': 'COMMIT'})
仍然使用 sparql = "DELETE DATA {}; INSERT DATA {}"。 内容类型为 'application/x-www-form-urlencoded' 和 url 编码的 sparql 字符串的请求。
在这种情况下,我会收到 406 错误
org.eclipse.rdf4j.http.server.ClientHTTPException: Could not read SPARQL update string from body.
【问题讨论】:
-
目前还不清楚您到底尝试了什么,出了什么问题。您能否更详细地说明您正在尝试做什么以及失败的地方?
-
请不要在问题文本中提供答案,而是将其发布为作为答案,然后将其标记为已接受的答案。这样,其他有相同问题的人可以更轻松地找到它。
-
另外:REST API 已在此处完整记录:rdf4j.eclipse.org/documentation/rest-api。可能比通过源代码更容易:)