From bc7590d8bff04ce8052d5394d065544c0f0b529c Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Tue, 20 Aug 2024 13:51:11 +0200 Subject: [PATCH] Use HTTPS to access World Bank SDMX endpoints Work around khaeru/sdmx#191 --- message_ix_models/tools/wb.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/message_ix_models/tools/wb.py b/message_ix_models/tools/wb.py index e76f449f6e..2873b26f5d 100644 --- a/message_ix_models/tools/wb.py +++ b/message_ix_models/tools/wb.py @@ -67,8 +67,12 @@ def get_weight(code: "sdmx.model.common.Code") -> float: return 1.0 elif method == "population": + # Work around khaeru/sdmx#191: ensure the HTTPS URL is used + client = sdmx.Client("WB_WDI") + client.source.url = client.source.url.replace("http://", "https://") + # Retrieve WB_WDI data for SERIES=SP_POP_TOTAL (Population, total) - dm = sdmx.Client("WB_WDI").data( + dm = client.data( "WDI", key="A.SP_POP_TOTL.", params=dict(startPeriod=2020, endPeriod=2020) ) @@ -154,7 +158,7 @@ def fetch_codelist(id: str) -> "sdmx.model.common.Codelist": import sdmx file = pooch.retrieve( - url="http://api.worldbank.org/v2/sdmx/rest/codelist/WB/", known_hash=None + url="https://api.worldbank.org/v2/sdmx/rest/codelist/WB/", known_hash=None ) # Read the retrieved SDMX StructureMessage and extract the code list sm = sdmx.read_sdmx(file)