From 5aa6047278d1d38d0db7c7d8aa475949c150c7a3 Mon Sep 17 00:00:00 2001 From: MarkCalvert <37602611+MarkCalvert@users.noreply.github.com> Date: Thu, 10 Aug 2023 16:21:48 +1200 Subject: [PATCH] Updated `sparql_json_vocabulary_terms` to use invalid_url helper which uses user-agent and retries to get response --- ckanext/vocabulary_services/logic/action/get.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ckanext/vocabulary_services/logic/action/get.py b/ckanext/vocabulary_services/logic/action/get.py index 0e43023..0250459 100644 --- a/ckanext/vocabulary_services/logic/action/get.py +++ b/ckanext/vocabulary_services/logic/action/get.py @@ -5,7 +5,7 @@ from ckan.plugins.toolkit import get_action from ckanext.vocabulary_services import helpers, model -from pprint import pformat +from ckanext.invalid_uris.helpers import valid_uri as uri_response from sqlalchemy import or_ log = logging.getLogger(__name__) @@ -56,14 +56,14 @@ def sparql_json_vocabulary_terms(context, data_dict): if service_id and service_uri: try: - r = requests.get(service_uri) - - log.debug('>>> Request status code: %s' % r.status_code) + result = uri_response(service_uri) + + log.debug('>>> Request status code: %s' % result.get('status_code')) - if r.status_code == 200: + if result.get('status_code') == 200 and result.get('response'): log.debug('>>> Finished fetching vocabulary from SPARQL+JSON service.') - response = r.json() + response = result.get('response').json() # If you open the https://vocabs.gsq.digital... URI above, you can see that the terms are # contained in the 'results' dict element, and the 'bindings' element beneath that.