fix: Handling cases where there is no result from the query

pull/340/head
chrisr3d 2019-10-08 13:28:23 +02:00
parent f27031d522
commit 5d4a0bff98
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
1 changed files with 3 additions and 4 deletions

View File

@ -26,13 +26,12 @@ def handler(q=False):
sparql.setQuery(query_string)
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
summary = ''
try:
result = results["results"]["bindings"][0]
summary = result["item"]["value"]
result = results["results"]["bindings"]
summary = result[0]["item"]["value"] if result else 'No additional data found on Wikidata'
except Exception as e:
misperrors['error'] = 'wikidata API not accessible' + e
misperrors['error'] = 'wikidata API not accessible {}'.format(e)
return misperrors['error']
r = {'results': [{'types': mispattributes['output'], 'values': summary}]}