1

I am having problem for running the following program (sparql_test.py). I am running it from Linux machine. I am installing Virtuoso server in the same Linux machine. In the Linux server, I don't have sudo permission nor browser access. But, I can execute SPARQL query from isql prompt (SQL>) successfully.

Program: 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

TallTed
  • 9,069
  • 2
  • 22
  • 37
  • 2
    `Bad gateway` is usually returned by a server that has troubles to talk to its backend servers. – Klaus D. Mar 23 '18 at 04:47
  • I agree with @KlausD., but what puzzles me is that the sparql query works from isql on the linux server, which means the server should have access to http://ehrofip.com/data/Admissions. – Henriette Harmse Mar 23 '18 at 07:58
  • Thanks KlausD.@HenrietteHarmse Yes, I can access data from ISQL prompt with port 1111, username and password. However, in case of sparql endpoint access, I have doubt with port number 8890. But I don't know how to test it as I don't have browser access. – Suresh Pokharel Mar 23 '18 at 08:54

1 Answers1

1

I do not believe this error is raised by Virtuoso. I believe it is raised by SPARQLWrapper.

It looks like there's something between the outside world (which includes the Linux machine itself) and the Virtuoso listener on port 8890. 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.

iSQL talks to port 1111 (set as [Parameters]:Listen in the INI file), which apparently doesn't have a similar block/proxy.

TallTed
  • 9,069
  • 2
  • 22
  • 37
  • Yes, I agree with @TallTed. I came to know port 8890 is blocked due to security reason. So, I can't access data from outside. Now, the question is can I access data from localhost i.e. within server? – Suresh Pokharel Mar 25 '18 at 23:54
  • Firewalls have lots of configuration options. By default, a blocked port is unreachable by any client, including localhost. Firewall configuration options often allow you to permit connections from one, many, or all clients. Only your system administrator can assist from here; we cannot guess at what you are permitted to do, nor what software is in play. Note that you can change Virtuoso's `HttpServer` `Listen` port from 8890 to an unblocked port (perhaps 1112, since 1111 is not blocked); then you'll have to change the client URI to match. – TallTed Mar 26 '18 at 13:32