Accessing OpenAnzo from Python

65 views
Skip to first unread message

Cerin

unread,
Mar 13, 2011, 5:21:11 PM3/13/11
to OpenAnzo
Is there a common methodology for accessing OpenAnzo RDF data from
Python? I'm trying to use librdf to access it as a Sparql endpoint
(e.g. http://librdf.org/docs/python.html), but I'm having trouble
determining the appropriate URI.

I have the sample OpenAnzo server running, and I've tried the Storage
call:

import RDF
storage=RDF.Storage(storage_name="uri",
name="http://localhost:8080/sparql",

options_string="username='sysadmin',password='123'")

but this fails with a 401 error, presumably because the http
authentication is blocking it. Does anyone know how to resolve this?

Regards,
Chris

Jordi Albornoz Mulligan

unread,
Mar 14, 2011, 11:07:36 AM3/14/11
to open...@googlegroups.com
Hi Chris,

On 3/13/2011 5:21 PM, Cerin wrote:
> Is there a common methodology for accessing OpenAnzo RDF data from
> Python?

There isn't a Python binding for the Open Anzo API so the SPARQL
endpoint is your best bet.

> I'm trying to use librdf to access it as a Sparql endpoint
> (e.g. http://librdf.org/docs/python.html), but I'm having trouble
> determining the appropriate URI.
>
> I have the sample OpenAnzo server running, and I've tried the Storage
> call:
>
> import RDF
> storage=RDF.Storage(storage_name="uri",
> name="http://localhost:8080/sparql",
>
> options_string="username='sysadmin',password='123'")
>
> but this fails with a 401 error, presumably because the http
> authentication is blocking it. Does anyone know how to resolve this?

I'm not familiar with the librdf python bindings but your URI seems
correct. And indeed, the 401 is what I would expect since the Open Anzo
SPARQL endpoint requires HTTP Basic Authentication. Are you sure that
librdf supports accessing a SPARQL endpoint that uses HTTP basic auth?

One thing you can try is using a lower level client like curl to verify
that the endpoint is working. A command like the following should work:
curl -u sysadmin:123 "http://localhost:8080/sparql/?query=SELECT..."

You may also find it useful to use a TCP proxy (like Apache TCPMon:
http://ws.apache.org/commons/tcpmon/) to inspect the traffic between the
python client and the server. In particular, that would show you if the
client is sending along the credentials via HTTP basic auth.

--
Jordi Albornoz Mulligan
Founding Engineer - Cambridge Semantics
jo...@cambridgesemantics.com
(617) 401-7321

Cerin

unread,
Mar 14, 2011, 9:55:06 PM3/14/11
to OpenAnzo
On Mar 14, 11:07 am, Jordi Albornoz Mulligan
<jo...@cambridgesemantics.com> wrote:
> Hi Chris,
>
> On 3/13/2011 5:21 PM, Cerin wrote:
>
> > Is there a common methodology for accessing OpenAnzo RDF data from
> > Python?
>
> There isn't a Python binding for the Open Anzo API so the SPARQL
> endpoint is your best bet.
>
> > I'm trying to use librdf to access it as a Sparql endpoint
> > (e.g.http://librdf.org/docs/python.html), but I'm having trouble
> > determining the appropriate URI.
>
> > I have the sample OpenAnzo server running, and I've tried the Storage
> > call:
>
> > import RDF
> > storage=RDF.Storage(storage_name="uri",
> >                      name="http://localhost:8080/sparql",
>
> > options_string="username='sysadmin',password='123'")
>
> > but this fails with a 401 error, presumably because the http
> > authentication is blocking it. Does anyone know how to resolve this?
>
> I'm not familiar with the librdf python bindings but your URI seems
> correct. And indeed, the 401 is what I would expect since the Open Anzo
> SPARQL endpoint requires HTTP Basic Authentication. Are you sure that
> librdf supports accessing a SPARQL endpoint that uses HTTP basic auth?

I just asked on the librdf mailing list, and they confirmed that they
neither support Sparql endpoints, nor basic auth. This is quite
depressing. I found a few Python libraries that specifically support
Sparql endpoints, but they've all been dead for a 2-3 years.

> One thing you can try is using a lower level client like curl to verify
> that the endpoint is working. A command like the following should work:
> curl -u sysadmin:123 "http://localhost:8080/sparql/?query=SELECT..."

Is it possible to add data to the server using the Sparql endpoint
alone?

I tried inserting a test triple with:

curl -u sysadmin:123 "http://localhost:8080/sparql/?query=INSERT DATA
{ <http://example.org/subject> <http://example.org/predicate> <http://
example.org/object> . }"

which didn't return any error response, but if I put the URL into a
browser, I get the error:

ErrorCode[4096:524307] [GLITTER_ERROR] Error parsing query, [INSERT
DATA { <http://example.org/subject> <http://example.org/predicate>
<http://example.org/object> . }] : Encountered "INSERT" at line 1,
column 1.
Was expecting one of:
"base" ...
"prefix" ...
"select" ...
"construct" ...
"ask" ...
"describe" ...
Root Cause: org.openanzo.glitter.syntax.concrete.ParseException
Encountered "INSERT" at line 1, column 1.
Was expecting one of:
"base" ...
"prefix" ...
"select" ...
"construct" ...
"ask" ...
"describe" ...

which I assume means that at best, Python would have a read-only
connection OpenAnzo?

Jordi Albornoz Mulligan

unread,
Mar 15, 2011, 1:31:26 PM3/15/11
to open...@googlegroups.com
On 3/14/2011 9:55 PM, Cerin wrote:
> On Mar 14, 11:07 am, Jordi Albornoz Mulligan

[snip]

>> I'm not familiar with the librdf python bindings but your URI seems
>> correct. And indeed, the 401 is what I would expect since the Open Anzo
>> SPARQL endpoint requires HTTP Basic Authentication. Are you sure that
>> librdf supports accessing a SPARQL endpoint that uses HTTP basic auth?
>
> I just asked on the librdf mailing list, and they confirmed that they
> neither support Sparql endpoints, nor basic auth. This is quite
> depressing. I found a few Python libraries that specifically support
> Sparql endpoints, but they've all been dead for a 2-3 years.

Perhaps you can try using Jython (http://www.jython.org/) to access the
Java Open Anzo API from python.

You can also just use regular python HTTP functionality to make your
SPARQL queries against the SPARQL endpoint and then possibly use librdf
to just parse the results and work with them. I can imagine especially
for CONSTRUCT queries that approach might be effective.

I'm not familiar enough with these approaches to know how well they
would work but they are some suggestions.

> Is it possible to add data to the server using the Sparql endpoint
> alone?

No. Not yet. Open Anzo doesn't yet support SPARQL UPDATE but will in the
future.

[snip]

> which I assume means that at best, Python would have a read-only
> connection OpenAnzo?

I mentioned Jython above as a way to access the Java API from python.
That would let you do inserts. I'm not sure of your overall task but if
it's for loading scripts or something like that, you can perhaps also
use the Open Anzo command line interface and invoke it from python.

Reply all
Reply to author
Forward
0 new messages