From 9fa49481f327943bb779d48968463d7c0aa645e3 Mon Sep 17 00:00:00 2001 From: Jean-Michel Crepel Date: Tue, 21 Oct 2025 17:49:31 +0200 Subject: [PATCH 1/2] detect version of geonetwork in order to target the good api subportail sources url --- geordash/api.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/geordash/api.py b/geordash/api.py index 0c1b834..bb5a4b0 100644 --- a/geordash/api.py +++ b/geordash/api.py @@ -151,8 +151,21 @@ def geonetwork_subportals(): headers = r[0] cookies = r[1] me = r[2] + + gn_site = requests.get(gnurl + "srv/api/site", cookies=cookies, headers=headers) + information_site = gn_site.json() + + # default url of subportal sources + subportalapiurl = "srv/api/sources" + if "4.4." in information_site['system/platform/version']: + # url for 4.4.8 + subportalapiurl = "srv/api/sources?type=subportal" + elif "4.2." in information_site['system/platform/version']: + # url for 4.2.8 + subportalapiurl = "srv/api/sources/subportal" + portals = requests.get( - gnurl + "srv/api/sources/subportal", cookies=cookies, headers=headers + gnurl + subportalapiurl, cookies=cookies, headers=headers ) if portals.status_code != 200: return portals.text From 4be378b1dfa180e48102d457ddd4b66922d0d2ea Mon Sep 17 00:00:00 2001 From: Jean-Michel Crepel Date: Wed, 22 Oct 2025 11:11:42 +0200 Subject: [PATCH 2/2] add safe call for getting the version of gn --- geordash/api.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/geordash/api.py b/geordash/api.py index bb5a4b0..623a4a4 100644 --- a/geordash/api.py +++ b/geordash/api.py @@ -152,15 +152,23 @@ def geonetwork_subportals(): cookies = r[1] me = r[2] - gn_site = requests.get(gnurl + "srv/api/site", cookies=cookies, headers=headers) - information_site = gn_site.json() + gn_site = requests.get(gnurl + "srv/api/site", headers={"Accept": "application/json"}) + information_site = {} + if gn_site.status_code == 200: + information_site = gn_site.json() + else: + app.logger.error( + f"Problem to detect the version of geonetwork with {gnurl}srv/api/site response {gn_site} \n" + f"Will try anyway to request the portal" + ) # default url of subportal sources subportalapiurl = "srv/api/sources" - if "4.4." in information_site['system/platform/version']: + # safely get the version from json answer + if "4.4." in information_site.get('system/platform/version', "Nop"): # url for 4.4.8 subportalapiurl = "srv/api/sources?type=subportal" - elif "4.2." in information_site['system/platform/version']: + elif "4.2." in information_site.get('system/platform/version', "Nop"): # url for 4.2.8 subportalapiurl = "srv/api/sources/subportal"