我正在尝试执行以下 Sparql 查询
select * where {
?s ?p ?o .
} limit 100
它运行良好并根据http://localhost:7200/sparql的要求产生结果,即 GraphDB Workbench。我想使用 python 进行相同的查询,为此我通过单击 GraphDB 界面中的“获取当前查询的 URL”来生成以下查询 URL。
http://localhost:7200/sparql?name=&infer=true&sameAs=false&query=select+*+where+%7B+%0A%09%3Fs+%3Fp+%3Fo+.%0A%7D+limit+100+%0A&execute=
我尝试为此编写 Python 代码
import pycurl
from StringIO import StringIO
url="http://localhost:7200/sparql?name=&infer=true&sameAs=false&query=select+*+where+%7B+%0A%09%3Fs+%3Fp+%3Fo+.%0A%7D+limit+100+%0A&execute="
response_buffer = StringIO()
curl = pycurl.Curl()
curl.setopt(curl.URL,url)
curl.setopt(curl.USERPWD, '%s:%s' % (' ' , ' '))
curl.setopt(curl.WRITEFUNCTION, response_buffer.write)
curl.perform()
curl.close()
response_value = response_buffer.getvalue()
print response_value
但是这会返回:错误 - http 状态 (404) - 没有消息,请查看服务器日志以获取更多信息
我是否需要为在 Python 中查询 GraphDB 做任何额外的设置。我可以得到一些关于如何使用 Python 和 Sparql 查询 GraphDB 的指导吗?