python - JSON decoding error when querying Wikidata
问题描述
I get a decoding error trying to decode my json data obtained from wikidata. I've read it may be because I'm trying to decode bytes instead of UTF-8 but I've tried to decode into UTF-8 and I can't seem to find the way to do so... Here's my method code (the parameter is a string and the return a boolean):
def es_enfermedad(candidato):
url = 'https://query.wikidata.org/sparql'
query = """
SELECT ?item WHERE {
?item rdfs:label ?nombre.
?item wdt:P31 ?tipo.
VALUES ?tipo {wd:Q12135}
FILTER(LCASE(?nombre) = "%s"@en)
}
""" % (candidato)
r = requests.get(url, params = {'format': 'json', 'query': query})
data = r.json()
return len(data['results']['bindings']) > 0
解决方案
推荐阅读
- css - text-transform: none 和 text-transform: initial 之间的区别
- javascript - 从 firebase angular-ionic 应用程序调用 http 云函数
- java - ClassLoader 找不到我的属性文件
- httprequest - 带有 DATAPLANE API 的 HAProxy http-request
- eclipse - Eclipse 删除资源窗口默认选中
- node.js - 电子商务产品的猫鼬模式
- python - 如何将文件拆分为字符
- c# - 避免反序列化类将多个项目添加到构造函数中的列表
- javascript - 为什么异步方法不按顺序执行?
- c# - 在net core中创建的wpf可执行文件中压缩dll