import urllib.parse
import requests
def urlencode(str):
  return urllib.parse.quote(str)


def urldecode(str):
  return urllib.parse.unquote(str)
query = """
PREFIX  efrbroo: <http://erlangen-crm.org/efrbroo/>
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
PREFIX  ecrm: <http://erlangen-crm.org/current/>

SELECT DISTINCT  ?person ?label ?wdPerson ?viaf WHERE { 
    ?person a efrbroo:F10_Person ;
        ecrm:P48_has_preferred_identifier/ecrm:P3_has_note ?label .
    OPTIONAL {
        ?person owl:sameAs  ?wdPerson
    }
  } LIMIT 10
"""
 
headers = {'Accept': 'application/json' }
url = 'http://db.sphaera.mpiwg-berlin.mpg.de/sparql?query='
r = requests.get(url + urlencode(query), headers=headers)
for person in r.json()['results']['bindings']:
    print(person)
{'person': {'type': 'uri', 'value': 'http://sphaera.mpiwg-berlin.mpg.de/id/person/0ae39e49-c449-4525-902f-16ee6c710951'}, 'label': {'type': 'literal', 'value': 'Burkardt, Adam'}, 'wdPerson': {'type': 'uri', 'value': 'https://www.wikidata.org/wiki/Q3604975'}}
{'person': {'type': 'uri', 'value': 'http://sphaera.mpiwg-berlin.mpg.de/id/person/0cc0d6a9-92e0-40bb-8f5a-06e19228efb3'}, 'label': {'type': 'literal', 'value': 'Baligault, Félix'}}
{'person': {'type': 'uri', 'value': 'http://sphaera.mpiwg-berlin.mpg.de/id/person/0d0d3171-144e-4978-b1da-4a69f71e7d5c'}, 'label': {'type': 'literal', 'value': 'Faber, Wenzel'}, 'wdPerson': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q2559749'}}
{'person': {'type': 'uri', 'value': 'http://sphaera.mpiwg-berlin.mpg.de/id/person/1148ee13-a4fd-4c06-99e0-ecf8ffa83394'}, 'label': {'type': 'literal', 'value': 'Anonymous'}}
{'person': {'type': 'uri', 'value': 'http://sphaera.mpiwg-berlin.mpg.de/id/person/229810bf-1d9e-4114-b3c7-ff87cbf5321d'}, 'label': {'type': 'literal', 'value': 'Sacrobosco, Johannes de'}, 'wdPerson': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q433841'}}
{'person': {'type': 'uri', 'value': 'http://sphaera.mpiwg-berlin.mpg.de/id/person/259c48a9-6f75-42cf-aa6f-159ce4c85e14'}, 'label': {'type': 'literal', 'value': 'Fontana, Giovanni'}, 'wdPerson': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q526613'}}
{'person': {'type': 'uri', 'value': 'http://sphaera.mpiwg-berlin.mpg.de/id/person/29903c4a-984a-482a-bc7a-24a78f4b0324'}, 'label': {'type': 'literal', 'value': 'Kachelofen, Konrad'}, 'wdPerson': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q1782143'}}
{'person': {'type': 'uri', 'value': 'http://sphaera.mpiwg-berlin.mpg.de/id/person/371c93a8-7149-4a35-a4e7-05cf31b7b6f8'}, 'label': {'type': 'literal', 'value': 'Mittelhus, Georges'}, 'wdPerson': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q3103205'}}
{'person': {'type': 'uri', 'value': 'http://sphaera.mpiwg-berlin.mpg.de/id/person/393e75c8-a638-46f6-93ae-93eae6df6275'}, 'label': {'type': 'literal', 'value': 'Romagnisius, Johannes'}}
{'person': {'type': 'uri', 'value': 'http://sphaera.mpiwg-berlin.mpg.de/id/person/09ecce91-97af-43ea-9b40-8ece0d0c80e2'}, 'label': {'type': 'literal', 'value': 'Szamotuł, Mateusz z'}, 'wdPerson': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q11771481'}}