khaeru / sdmx

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

`RuntimeError` when using `key` on data request #94

Open apfister opened 2 years ago

apfister commented 2 years ago

When running this code, I receive a RuntimeError shown below:

spc = sdmx.Client('spc')

key = dict(FREQ=['A'])
params = dict(startPeriod='2021', endPeriod='2022')

data = spc.data('DF_SDG', key=key, params=params)

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
File ~/opt/anaconda3/lib/python3.8/site-packages/sdmx/reader/xml.py:242, in Reader.read_message(self, source, dsd)
    240 try:
    241     # Parse the element
--> 242     result = func(self, element)
    243 except TypeError:

File ~/opt/anaconda3/lib/python3.8/site-packages/sdmx/reader/xml.py:1126, in _ms(reader, elem)
   1125 else:
-> 1126     raise RuntimeError
   1128 if arg["values_for"] is None:

RuntimeError: 

The above exception was the direct cause of the following exception:

XMLParseError                             Traceback (most recent call last)
/Users/adam6475/dev/sdg-template-connectors/sdmx/retry.ipynb Cell 9' in <cell line: 6>()
      [3](vscode-notebook-cell:/Users/adam6475/dev/sdg-template-connectors/sdmx/retry.ipynb#ch0000009?line=2) key = dict(FREQ=['A'])
      [4](vscode-notebook-cell:/Users/adam6475/dev/sdg-template-connectors/sdmx/retry.ipynb#ch0000009?line=3) params = dict(startPeriod='2021', endPeriod='2022')
----> [6](vscode-notebook-cell:/Users/adam6475/dev/sdg-template-connectors/sdmx/retry.ipynb#ch0000009?line=5) data = spc.data('DF_SDG', key=key, params=params)

File ~/opt/anaconda3/lib/python3.8/site-packages/sdmx/client.py:440, in Client.get(self, resource_type, resource_id, tofile, use_cache, dry_run, **kwargs)
    438     req = self._request_from_url(kwargs)
...
    263 
    264 # Remove some internal items
    265 self.pop_single("SS without DSD")

XMLParseError: RuntimeError

if you run the code without the key parameters, there is no error:

spc = sdmx.Client('spc')

# key = dict(FREQ=['A'])
params = dict(startPeriod='2021', endPeriod='2022')

data = spc.data('DF_SDG', params=params)
image
khaeru commented 1 year ago

Thanks for the report!

File ~/opt/anaconda3/lib/python3.8/site-packages/sdmx/reader/xml.py:1126, in _ms(reader, elem)
   1125 else:
-> 1126     raise RuntimeError

This (_ms(reader, elem)) indicates the error occurs when parsing a MemberSelection object from an XML <com:Attribute> or <com:KeyValue> tag. This is probably either (a) some valid SDMX feature/usage that we have not seen in the wild, or (b) some invalid SDMX being returned by this data provider.

The log output should give the exact URL that is queried. Can you please give this URL and/or attach the XML file that is returned? This will help me to: