hi every one
i have a query in python, which requests an sparql query to dbpedia.
i want to get triples with special object.
here is my query:
query='''
PREFIX rs: <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
select distinct ?sub,?predicate
where
{{
?sub ?predicate rs:{a1}.
}}
'''.format(a1=ent)
url = 'https://dbpedia.org/sparql/'
myobj = {"query":query, "format":"json", "default-graph-uri":"http://dbpedia.org"}
try:
r=requests.get(url, params=myobj)
except Exception as ex:
print("error for question for entity:"+ent+" : ",ex)
but the problem is when my object has special characters, i get 400 from dbpedia.
here is some examples that had bad request.
error for question for entity:Off_Limits_(1988_film) : Expecting value: line 1 column 1 (char 0)
error for question for entity:Faith_of_My_Fathers_(film) : Expecting value: line 1 column 1 (char 0)
error for question for entity:A_Rumor_of_War_(miniseries) : Expecting value: line 1 column 1 (char 0)
error for question for entity:Bat*21 : Expecting value: line 1 column 1 (char 0)
error for question for entity:Hearts_and_Minds_(film) : Expecting value: line 1 column 1 (char 0)
error for question for entity:The_Green_Berets_(film) : Expecting value: line 1 column 1 (char 0)
error for question for entity:War_in_Vietnam_(1954–59) : Expecting value: line 1 column 1 (char 0)
error for question for entity:Alice's_Restaurant_(film) : Expecting value: line 1 column 1 (char 0)
error for question for entity:Sir!_No_Sir! : Expecting value: line 1 column 1 (char 0)
error for question for entity:Jacob's_Ladder_(film) : Expecting value: line 1 column 1 (char 0)
error for question for entity:List_of_allied_military_operations_of_the_Vietnam_War_(1973–74) : Expecting value: line 1 column 1 (char 0)
error for question for entity:War_in_Vietnam_(1945–46) : Expecting value: line 1 column 1 (char 0)
error for question for entity:The_War_at_Home_(film) : Expecting value: line 1 column 1 (char 0)
error for question for entity:Missing_in_Action_(film) : Expecting value: line 1 column 1 (char 0)
<Response [400]>
error for question for entity:Off_Limits_(1988_film) : Expecting value: line 1 column 1 (char 0)
so how can i request to dbpedia in python correctly?