khaeru / sdmx

SDMX information model and client in Python
https://sdmx1.readthedocs.io
Apache License 2.0
24 stars 18 forks source link

Detect SDMX version #176

Open SanderNielen opened 5 months ago

SanderNielen commented 5 months ago

The eurostat API URL has a structure of /sdmx/2.1/. This is not recognized by the current script.

Suggested change in sdmx/reader/xml/__init__.py: Line 34: if "v3_0" in url or "3.0" in url: Line 37: elif "v2_1" in url or "2.1" in url:

khaeru commented 5 months ago

Hi @SanderNielen —thanks for your note.

In https://github.com/khaeru/sdmx/pull/158#issuecomment-1935661023 I added ESTAT3, which speaks to Eurostat's SDMX 3.0.0 / SDMX-REST 2.1.0 endpoint, while ESTAT continues to query the base URL you mention, using SDMX-REST 1.5.0 and expecting responses in SDMX-ML 2.1. You can confirm this by looking at sources.json. Both also appear in the docs (though perhaps there could be more detail here), and are tested.

So your comment “not recognized by the current script” is, unfortunately, not precise enough to determine what kind of issue you're having. Can you please provide a minimal working example that demonstrates whatever error or unexpected outcome, and the full detail of that error message, traceback, etc.?

SanderNielen commented 5 months ago

Do you mean I should just use sdmx.Client("ESTAT3")?

The code that produces the error is:

estat = sdmx.Client("ESTAT")
dataflows = estat.dataflow().dataflow
data_msg = estat.data("LFSO_05REGCP") # Example of a dataset code

The error traceback from sdmx1 version 2.14.0 is:

File "C:\***\sdmx\client.py", line 496, in get
  msg = reader.read_message(response_content, structure=kwargs.get("dsd", None))

File "C:\***\sdmx\reader\xml\__init__.py", line 40, in read_message
  assert version, f"Cannot determine SDMX-ML version of url"

(Note: this also happens when the requested table is too large.)