简体   繁体   English

在Linux中从python执行sparql查询到virtuoso服务器?

[英]Executing sparql query from python to virtuoso server in linux?

I am having problem for running the following program ( sparql_test.py ). 我在运行以下程序( sparql_test.py )时遇到问题。 I am running it from Linux machine. 我正在Linux机器上运行它。 I am installing Virtuoso server in the same Linux machine. 我正在同一台Linux机器上安装Virtuoso服务器。 In the Linux server, I don't have sudo permission nor browser access. 在Linux服务器中,我没有sudo权限,也没有浏览器访问权限。 But, I can execute SPARQL query from isql prompt ( SQL> ) successfully. 但是,我可以从isql提示符( SQL> )成功执行SPARQL查询。

Program: sparql_test.py 程式: sparql_test.py

from SPARQLWrapper import SPARQLWrapper, JSON
sparql = SPARQLWrapper("http://localhost:8890/sparql")
sparql.setQuery("select ?s where { ?s a <http://ehrofip.com/data/Admissions>.} limit  10")
sparql.setReturnFormat(JSON)
result = sparql.query().convert()
for res in result["results"]["bindings"]:
    print(res)

I got the following error: 我收到以下错误:

[suresh@deodar complex2vec]$ python sparql_test.py
Traceback (most recent call last):
File "sparql1.py", line 14, in "<module>"
  result = sparql.query().convert()
File "/home/suresh/.local/lib/python2.7/site-packages/SPARQLWrapper/Wrapper.py", line 687, in query
  return QueryResult(self._query())
File "/home/suresh/.local/lib/python2.7/site-packages/SPARQLWrapper/Wrapper.py", line 667, in _query
  raise e
urllib2.HTTPError: HTTP Error 502: Bad Gateway

However, the above program run smoothly in my own laptop. 但是,以上程序可以在我自己的笔记本电脑上流畅运行。 What might be the problem? 可能是什么问题? Is this issue of connection? 这是连接问题吗?

Thank you 谢谢

Best, 最好,

Suresh 苏雷什

I do not believe this error is raised by Virtuoso. 我不相信Virtuoso会引发此错误。 I believe it is raised by SPARQLWrapper. 我相信它是由SPARQLWrapper提出的。

It looks like there's something between the outside world (which includes the Linux machine itself) and the Virtuoso listener on port 8890 . 外部环境(包括Linux机器本身)和端口8890上的Virtuoso侦听器之间似乎存在某种关系。 The "Bad Gateway" suggests there may be two things -- a reverse proxy, and a firewall. “错误的网关”表明可能有两件事-反向代理和防火墙。

Port 8890 (set as [HttpServer]:Listen in the INI file) must be open to communications, direct or proxied, for SPARQL access to work. 必须打开端口8890(在INI文件中设置为[HttpServer]:Listen ),以便直接或代理进行通信,以使SPARQL能够正常工作。

iSQL talks to port 1111 (set as [Parameters]:Listen in the INI file), which apparently doesn't have a similar block/proxy. iSQL与端口1111(在INI文件中设置为[Parameters]:Listen )进行通信,该端口显然没有类似的块/代理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM