Skip to content

Instantly share code, notes, and snippets.

@anarchivist
Created March 20, 2016 22:03
Show Gist options
  • Select an option

  • Save anarchivist/b3bbcdd132acb0a9a1bc to your computer and use it in GitHub Desktop.

Select an option

Save anarchivist/b3bbcdd132acb0a9a1bc to your computer and use it in GitHub Desktop.
Using HTTP Basic authentication to fetch resources in a Fedora 4 demo install for parsing with RDFLib
import urllib2
from rdflib import Graph, URIRef, Literal
# Register an authentication handler
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm='fcrepo', uri="http://localhost:8080/fcrepo/rest", user="fedoraAdmin", passwd="secret3")
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
# Create a new rdflib Graph object and parse the remote resource
g = Graph()
g.parse("http://localhost:8080/fcrepo/rest/cover")
# <Graph identifier=N9e321401ad4346cf888708c01c7e91e7 (<class 'rdflib.graph.Graph'>)>
for _ in g:
print _
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment