SPARQLWrapper and Cookies

12 views
Skip to first unread message

adamfk...@gmail.com

unread,
Oct 31, 2018, 12:23:28 PM10/31/18
to rdflib-dev
Hi all,

I'd like to use SPARQLWrapper to query an endpoint that requires authorization.  Sadly, the authorization is form based, so I need to fetch an initial cookie, post username/password and then hold on to that cookie for every subsequent query.  I don't see an easy way to do this.  Is there an example floating around that might be of help to me?

Thanks,
Adam

Gunnar Aastrand Grimnes

unread,
Nov 1, 2018, 4:46:16 AM11/1/18
to rdfli...@googlegroups.com
If you use the soon to be released 5.0.0 of RDFLib (i.e. head of git
master) and you need a Graph and not just a query, you can do:

import rdflib
from rdflib.plugins.stores.sparqlstore import SPARQLStore

import requests
r = requests.post( ... whatever ...)
jar = r.cookies

store = SPARQLStore('http://localhost:8000', cookies=jar)
g = rdflib.Graph(store)

Any query performed by this graph will now use your cookies.

- Gunnar
> --
> http://github.com/RDFLib
> ---
> You received this message because you are subscribed to the Google Groups "rdflib-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+...@googlegroups.com.
> To post to this group, send email to rdfli...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/25f8f5e4-8884-4368-b0d9-e55f926826fc%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
http://gromgull.net
Reply all
Reply to author
Forward
0 new messages