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
[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.