diff --git a/geordash/api.py b/geordash/api.py index 0c1b834..623a4a4 100644 --- a/geordash/api.py +++ b/geordash/api.py @@ -151,8 +151,29 @@ def geonetwork_subportals(): headers = r[0] cookies = r[1] me = r[2] + + 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" + # 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.get('system/platform/version', "Nop"): + # 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