Abhimanyu Anand
Abhimanyu Anand

Reputation: 13

RuntimeWarning: unknown response content type 'text/html; charset=UTF-8' returning raw response

I am trying to fetch details using the SPARQLWrapper and JSON format from the dbpedia database.

This is my code:

from SPARQLWrapper import SPARQLWrapper, JSON

sparql = SPARQLWrapper("http://dbpedia.org")
sparql.setReturnFormat(JSON)
sparql.setQuery("""
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?birth_date ?birth_place
WHERE {
?name rdfs:label "Ed Sheeran"@en .
?name dbo:birthDate ?birth_date .
?name dbo:birthPlace ?birth_place .
}"""
)

try:
    ret = sparql.queryAndConvert()
    ret = ret.decode('utf-8')
    # print(ret)
    # for r in ret["results"]["bindings"]:
    #     print(r)
except Exception as e:
    print(e)

I get a giant result when I print(ret) but it doesn't print the result at all and gives the warning -

RuntimeWarning: unknown response content type 'text/html; charset=UTF-8' returning raw response...
  warnings.warn(

The query returns Ed Sheeran's birth date and birth place as expected in the JSON format when I try it in the official SPARQL query for DBPedia. Query

Result

What am I doing wrong here?

Upvotes: 0

Views: 256

Answers (0)

Related Questions